Home | History | Annotate | Download | only in Domains
      1 # -*-coding:utf-8 -*
      2 
      3 # Copyright (c) 2011-2015, Intel Corporation
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without modification,
      7 # are permitted provided that the following conditions are met:
      8 #
      9 # 1. Redistributions of source code must retain the above copyright notice, this
     10 # list of conditions and the following disclaimer.
     11 #
     12 # 2. Redistributions in binary form must reproduce the above copyright notice,
     13 # this list of conditions and the following disclaimer in the documentation and/or
     14 # other materials provided with the distribution.
     15 #
     16 # 3. Neither the name of the copyright holder nor the names of its contributors
     17 # may be used to endorse or promote products derived from this software without
     18 # specific prior written permission.
     19 #
     20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     23 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
     24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     27 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30 
     31 """
     32 Renaming domains testcases
     33 
     34 List of tested functions :
     35 --------------------------
     36     - [renameDomain]  function
     37 
     38 Test cases :
     39 ------------
     40     - Nominal cases
     41     - Renaming errors
     42     - Special cases
     43 """
     44 import os
     45 from Util.PfwUnitTestLib import PfwTestCase
     46 from Util import ACTLogging
     47 log=ACTLogging.Logger()
     48 
     49 # Test of Domains - Rename
     50 class TestCases(PfwTestCase):
     51     def setUp(self):
     52         self.pfw.sendCmd("setTuningMode", "on")
     53         self.domain_name = "domain_white"
     54         self.new_domain_name = "domain_black"
     55         self.renaming_iterations = 5
     56 
     57     def tearDown(self):
     58         self.pfw.sendCmd("setTuningMode", "off")
     59 
     60     def test_Nominal_Case(self):
     61         """
     62         Nominal case
     63         ------------
     64             Test case description :
     65             ~~~~~~~~~~~~~~~~~~~~~~~
     66                 - Renaming a domain
     67             Tested commands :
     68             ~~~~~~~~~~~~~~~~~
     69                 - [renameDomain] function
     70                 - [createDomain] function
     71                 - [listDomains] function
     72             Expected result :
     73             ~~~~~~~~~~~~~~~~~
     74                 - domains correctly renamed
     75         """
     76         log.D(self.test_Nominal_Case.__doc__)
     77         # New domain creation
     78         log.I("New domain creation : %s" % (self.domain_name))
     79         log.I("command [createDomain]" )
     80         out, err = self.pfw.sendCmd("createDomain",self.domain_name, "")
     81         assert out == "Done", out
     82         assert err == None, "ERROR : command [createDomain] - ERROR while creating domain %s" % (self.domain_name)
     83         log.I("command [createDomain] correctly executed")
     84         log.I("Domain %s created" % (self.domain_name))
     85 
     86         # Initial domains listing using "listDomains" command
     87         log.I("Creating a domains listing backup")
     88         log.I("command [listDomains]")
     89         out, err = self.pfw.sendCmd("listDomains","","")
     90         assert err == None, "INFO : command [listDomains] - ERROR while listing domains"
     91         log.I("command [listDomains] correctly executed")
     92         # Saving initial domains names
     93         f_init_domains = open("f_init_domains", "w")
     94         f_init_domains.write(out)
     95         f_init_domains.close()
     96         log.I("Domains listing backup created")
     97 
     98         # Checking domains number
     99         f_init_domains = open("f_init_domains", "r")
    100         domains_nbr = 0
    101         line=f_init_domains.readline()
    102         while line!="":
    103             line=f_init_domains.readline()
    104             domains_nbr+=1
    105         f_init_domains.close()
    106         os.remove("f_init_domains")
    107         log.I("%s domains names saved" % domains_nbr)
    108 
    109         # Domain renaming iterations
    110         log.I("Checking domain renaming - %s iterations" % self.renaming_iterations)
    111         old_name = self.domain_name
    112         new_name = self.new_domain_name
    113         for iteration in range (self.renaming_iterations):
    114             log.I("Iteration %s" % (iteration))
    115             log.I("Renaming domain %s to %s" % (old_name,new_name))
    116             log.I("command [renameDomain]")
    117             out, err = self.pfw.sendCmd("renameDomain",old_name,new_name)
    118             assert out == "Done", out
    119             assert err == None, "ERROR : command [renameDomain] - ERROR while renaming domain %s" % (old_name)
    120             # Domains listing using "listDomains" command
    121             log.I("Creating a domains listing")
    122             log.I("command [listDomains]")
    123             out, err = self.pfw.sendCmd("listDomains","","")
    124             assert err == None, "ERROR : command [listDomains] - ERROR while listing domains"
    125             log.I("command [listDomains] correctly executed")
    126             # Saving domains names
    127             f_domains = open("f_domains", "w")
    128             f_domains.write(out)
    129             f_domains.close()
    130             log.I("Domains listing created")
    131             # Checking renaming
    132             log.I("Checking that renaming is correct in domains listing")
    133             f_domains = open("f_domains", "r")
    134             for line in range(domains_nbr):
    135                 if (line >= (domains_nbr - 1)):
    136                     domain_renamed = f_domains.readline().strip('\n')
    137                     assert domain_renamed==new_name, "ERROR : Error while renaming domain %s" % (old_name)
    138                 else:
    139                     f_domains.readline()
    140             f_domains.close()
    141             log.I("New domain name %s conform to expected value" % (new_name))
    142             temp = old_name
    143             old_name = new_name
    144             new_name = temp
    145             os.remove("f_domains")
    146 
    147     def test_Renaming_Error(self):
    148         """
    149         Renaming errors
    150         ---------------
    151             Test case description :
    152             ~~~~~~~~~~~~~~~~~~~~~~~
    153                 - renaming a non existent domain
    154                 - renaming a domain with an already existent domain name
    155             Tested commands :
    156             ~~~~~~~~~~~~~~~~~
    157                 - [renameDomain] function
    158                 - [createDomain] function
    159                 - [renameDomain] function
    160             Expected result :
    161             ~~~~~~~~~~~~~~~~~
    162                 - error detected
    163                 - domains names remain unchanged
    164         """
    165         log.D(self.test_Renaming_Error.__doc__)
    166         # New domains creation
    167         log.I("New domain creation : %s" % (self.domain_name))
    168         log.I("command [createDomain]")
    169         out, err = self.pfw.sendCmd("createDomain",self.domain_name, "")
    170         assert out == "Done", out
    171         assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name)
    172         log.I("command [createDomain] - correctly executed")
    173         log.I("command Domain %s created" % (self.domain_name))
    174 
    175         # Initial domains listing using "listDomains" command
    176         log.I("Creating a domains listing backup")
    177         log.I("command [listDomains]")
    178         out, err = self.pfw.sendCmd("listDomains","","")
    179         assert err == None, "INFO : command [listDomains] - Error while listing domains"
    180         log.I("command [listDomains] correctly executed")
    181         # Saving initial domains names
    182         f_init_domains = open("f_init_domains", "w")
    183         f_init_domains.write(out)
    184         f_init_domains.close()
    185         log.I("Domains listing backup created")
    186 
    187         # Checking domains number
    188         f_init_domains = open("f_init_domains", "r")
    189         domains_nbr = 0
    190         line=f_init_domains.readline()
    191         while line!="":
    192             line=f_init_domains.readline()
    193             domains_nbr+=1
    194         f_init_domains.close()
    195         log.I("%s domains names saved" % domains_nbr)
    196 
    197         # Domain renaming error : renamed domain does not exist
    198         log.I("Renaming a non existent domain")
    199         log.I("Renaming domain FAKE to NEW_NAME")
    200         log.I("command [renameDomain]")
    201         out, err = self.pfw.sendCmd("renameDomain",'FAKE','NEW_NAME', expectSuccess=False)
    202         assert out != "Done", out
    203         assert err == None, "ERROR : command [renameDomain] - Error while renaming domain"
    204         log.I("command [renameDomain] - renaming error correctly detected")
    205         # Domains listing using "listDomains" command
    206         log.I("Creating a domains listing")
    207         log.I("command [listDomains]")
    208         out, err = self.pfw.sendCmd("listDomains","","")
    209         assert err == None, "ERROR : command [listDomains] - Error while listing domains"
    210         log.I("command [listDomains] correctly executed")
    211         # Saving domains names
    212         f_domains = open("f_domains", "w")
    213         f_domains.write(out)
    214         f_domains.close()
    215         log.I("Domains listing created")
    216         # Checking domains names integrity
    217         log.I("Checking domains names integrity")
    218         f_domains = open("f_domains", "r")
    219         f_init_domains = open("f_init_domains", "r")
    220         for line in range(domains_nbr):
    221             domain_name = f_domains.readline().strip('\n')
    222             domain_backup_name = f_init_domains.readline().strip('\n')
    223             assert domain_name==domain_backup_name, "ERROR : Domain name %s affected by the renaming error" % (domain_backup_name)
    224         f_domains.close()
    225         f_init_domains.close()
    226         log.I("Domains names not affected by the renaming error")
    227         os.remove("f_domains")
    228 
    229         # Domain renaming error : renaming a domain with an already existent domain name
    230         log.I("renaming a domain with an already existent domain name")
    231         log.I("Renaming domain %s to %s" % (self.domain_name,self.new_domain_name) )
    232         log.I("command [renameDomain]")
    233         out, err = self.pfw.sendCmd("renameDomain",self.domain_name,self.new_domain_name, expectSuccess=False)
    234         assert out != "Done", out
    235         assert err == None, "INFO : command [renameDomain] - Error while renaming domain"
    236         log.I("command [renameDomain] - renaming error correctly detected")
    237         # Domains listing using "listDomains" command
    238         log.I("Creating a domains listing")
    239         log.I("command [listDomains]")
    240         out, err = self.pfw.sendCmd("listDomains","","")
    241         assert err == None, "ERROR : command [listDomains] - Error while listing domains"
    242         log.I("command [listDomains] correctly executed")
    243         # Saving domains names
    244         f_domains = open("f_domains", "w")
    245         f_domains.write(out)
    246         f_domains.close()
    247         log.I("Domains listing created")
    248         # Checking domains names integrity
    249         log.I("Checking domains names integrity")
    250         f_domains = open("f_domains", "r")
    251         f_init_domains = open("f_init_domains", "r")
    252         for line in range(domains_nbr):
    253             domain_name = f_domains.readline().strip('\n')
    254             domain_backup_name = f_init_domains.readline().strip('\n')
    255             assert domain_name==domain_backup_name, "ERROR : domain name %s affected by the renaming error" % (domain_backup_name)
    256         f_domains.close()
    257         f_init_domains.close()
    258         log.I("Domains names not affected by the renaming error")
    259         os.remove("f_domains")
    260         os.remove("f_init_domains")
    261 
    262     def test_Special_Cases(self):
    263         """
    264         Special cases
    265         -------------
    266             Test case description :
    267             ~~~~~~~~~~~~~~~~~~~~~~~
    268                 - renaming a domain with its own name
    269             Tested commands :
    270            ~~~~~~~~~~~~~~~~~
    271                 - [renameDomain] function
    272                 - [createDomain] function
    273                 - [listDomains] function
    274             Expected result :
    275             ~~~~~~~~~~~~~~~~~
    276                 - no error
    277                 - domains names remain unchanged
    278         """
    279         log.D(self.test_Special_Cases.__doc__)
    280         # New domain creation
    281         # Already created in previous test
    282 
    283         # Initial domains listing using "listDomains" command
    284         log.I("Creating a domains listing backup")
    285         log.I("command [listDomains]")
    286         out, err = self.pfw.sendCmd("listDomains","","")
    287         assert err == None, "ERROR : command [listDomains] - Error while listing domains"
    288         log.I("command [listDomains] correctly executed")
    289         # Saving initial domains names
    290         f_init_domains = open("f_init_domains", "w")
    291         f_init_domains.write(out)
    292         f_init_domains.close()
    293         log.I("Domains listing backup created")
    294 
    295         # Checking domains number
    296         f_init_domains = open("f_init_domains", "r")
    297         domains_nbr = 0
    298         line=f_init_domains.readline()
    299         while line!="":
    300             line=f_init_domains.readline()
    301             domains_nbr+=1
    302         f_init_domains.close()
    303         log.I("%s domains names saved" % domains_nbr)
    304 
    305         # Domain renaming error : renaming a domain with its own name
    306         log.I("renaming a domain with its own name")
    307         log.I("Renaming domain %s to %s" % (self.domain_name,self.domain_name))
    308         log.I("command [renameDomain]")
    309         out, err = self.pfw.sendCmd("renameDomain",self.domain_name,self.domain_name)
    310         assert out == "Done", out
    311         assert err == None, "ERROR : command [renameDomain] - Error while renaming domain"
    312         log.I("command [renameDomain] correctly executed")
    313         # Domains listing using "listDomains" command
    314         log.I("Creating a domains listing")
    315         log.I("command [listDomains]")
    316         out, err = self.pfw.sendCmd("listDomains","","")
    317         assert err == None, "ERROR : command [listDomains] - Error while listing domains"
    318         log.I("command [listDomains] correctly executed")
    319         # Saving domains names
    320         f_domains = open("f_domains", "w")
    321         f_domains.write(out)
    322         f_domains.close()
    323         log.I("Domains listing created")
    324         # Checking domains names integrity
    325         log.I("Checking domains names integrity")
    326         f_domains = open("f_domains", "r")
    327         f_init_domains = open("f_init_domains", "r")
    328         for line in range(domains_nbr):
    329             domain_name = f_domains.readline().strip('\n')
    330             domain_backup_name = f_init_domains.readline().strip('\n')
    331             assert domain_name==domain_backup_name, "ERROR : domain name %s affected by the renaming" % (domain_backup_name)
    332         f_domains.close()
    333         f_init_domains.close()
    334         log.I("Domains names not affected by the renaming")
    335 
    336         os.remove("f_domains")
    337         os.remove("f_init_domains")
    338