summaryrefslogtreecommitdiffstats
path: root/test/functional-tests/PfwTestCase/Domains/tDomain_rename.py
blob: 81d4539e6f7f1ebb00543ac864511f0b0f9cdef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# -*-coding:utf-8 -*

# Copyright (c) 2011-2015, Intel Corporation
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
Renaming domains testcases

List of tested functions :
--------------------------
    - [renameDomain]  function

Test cases :
------------
    - Nominal cases
    - Renaming errors
    - Special cases
"""
import os
from Util.PfwUnitTestLib import PfwTestCase
from Util import ACTLogging
log=ACTLogging.Logger()

# Test of Domains - Rename
class TestCases(PfwTestCase):
    def setUp(self):
        self.pfw.sendCmd("setTuningMode", "on")
        self.domain_name = "domain_white"
        self.new_domain_name = "domain_black"
        self.renaming_iterations = 5

    def tearDown(self):
        self.pfw.sendCmd("setTuningMode", "off")

    def test_Nominal_Case(self):
        """
        Nominal case
        ------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Renaming a domain
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [renameDomain] function
                - [createDomain] function
                - [listDomains] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - domains correctly renamed
        """
        log.D(self.test_Nominal_Case.__doc__)
        # New domain creation
        log.I("New domain creation : %s" % (self.domain_name))
        log.I("command [createDomain]" )
        out, err = self.pfw.sendCmd("createDomain",self.domain_name, "")
        assert out == "Done", out
        assert err == None, "ERROR : command [createDomain] - ERROR while creating domain %s" % (self.domain_name)
        log.I("command [createDomain] correctly executed")
        log.I("Domain %s created" % (self.domain_name))

        # Initial domains listing using "listDomains" command
        log.I("Creating a domains listing backup")
        log.I("command [listDomains]")
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "INFO : command [listDomains] - ERROR while listing domains"
        log.I("command [listDomains] correctly executed")
        # Saving initial domains names
        f_init_domains = open("f_init_domains", "w")
        f_init_domains.write(out)
        f_init_domains.close()
        log.I("Domains listing backup created")

        # Checking domains number
        f_init_domains = open("f_init_domains", "r")
        domains_nbr = 0
        line=f_init_domains.readline()
        while line!="":
            line=f_init_domains.readline()
            domains_nbr+=1
        f_init_domains.close()
        os.remove("f_init_domains")
        log.I("%s domains names saved" % domains_nbr)

        # Domain renaming iterations
        log.I("Checking domain renaming - %s iterations" % self.renaming_iterations)
        old_name = self.domain_name
        new_name = self.new_domain_name
        for iteration in range (self.renaming_iterations):
            log.I("Iteration %s" % (iteration))
            log.I("Renaming domain %s to %s" % (old_name,new_name))
            log.I("command [renameDomain]")
            out, err = self.pfw.sendCmd("renameDomain",old_name,new_name)
            assert out == "Done", out
            assert err == None, "ERROR : command [renameDomain] - ERROR while renaming domain %s" % (old_name)
            # Domains listing using "listDomains" command
            log.I("Creating a domains listing")
            log.I("command [listDomains]")
            out, err = self.pfw.sendCmd("listDomains","","")
            assert err == None, "ERROR : command [listDomains] - ERROR while listing domains"
            log.I("command [listDomains] correctly executed")
            # Saving domains names
            f_domains = open("f_domains", "w")
            f_domains.write(out)
            f_domains.close()
            log.I("Domains listing created")
            # Checking renaming
            log.I("Checking that renaming is correct in domains listing")
            f_domains = open("f_domains", "r")
            for line in range(domains_nbr):
                if (line >= (domains_nbr - 1)):
                    domain_renamed = f_domains.readline().strip('\n')
                    assert domain_renamed==new_name, "ERROR : Error while renaming domain %s" % (old_name)
                else:
                    f_domains.readline()
            f_domains.close()
            log.I("New domain name %s conform to expected value" % (new_name))
            temp = old_name
            old_name = new_name
            new_name = temp
            os.remove("f_domains")

    def test_Renaming_Error(self):
        """
        Renaming errors
        ---------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - renaming a non existent domain
                - renaming a domain with an already existent domain name
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [renameDomain] function
                - [createDomain] function
                - [renameDomain] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - error detected
                - domains names remain unchanged
        """
        log.D(self.test_Renaming_Error.__doc__)
        # New domains creation
        log.I("New domain creation : %s" % (self.domain_name))
        log.I("command [createDomain]")
        out, err = self.pfw.sendCmd("createDomain",self.domain_name, "")
        assert out == "Done", out
        assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (self.domain_name)
        log.I("command [createDomain] - correctly executed")
        log.I("command Domain %s created" % (self.domain_name))

        # Initial domains listing using "listDomains" command
        log.I("Creating a domains listing backup")
        log.I("command [listDomains]")
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "INFO : command [listDomains] - Error while listing domains"
        log.I("command [listDomains] correctly executed")
        # Saving initial domains names
        f_init_domains = open("f_init_domains", "w")
        f_init_domains.write(out)
        f_init_domains.close()
        log.I("Domains listing backup created")

        # Checking domains number
        f_init_domains = open("f_init_domains", "r")
        domains_nbr = 0
        line=f_init_domains.readline()
        while line!="":
            line=f_init_domains.readline()
            domains_nbr+=1
        f_init_domains.close()
        log.I("%s domains names saved" % domains_nbr)

        # Domain renaming error : renamed domain does not exist
        log.I("Renaming a non existent domain")
        log.I("Renaming domain FAKE to NEW_NAME")
        log.I("command [renameDomain]")
        out, err = self.pfw.sendCmd("renameDomain",'FAKE','NEW_NAME')
        assert out != "Done", out
        assert err == None, "ERROR : command [renameDomain] - Error while renaming domain"
        log.I("command [renameDomain] - renaming error correctly detected")
        # Domains listing using "listDomains" command
        log.I("Creating a domains listing")
        log.I("command [listDomains]")
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "ERROR : command [listDomains] - Error while listing domains"
        log.I("command [listDomains] correctly executed")
        # Saving domains names
        f_domains = open("f_domains", "w")
        f_domains.write(out)
        f_domains.close()
        log.I("Domains listing created")
        # Checking domains names integrity
        log.I("Checking domains names integrity")
        f_domains = open("f_domains", "r")
        f_init_domains = open("f_init_domains", "r")
        for line in range(domains_nbr):
            domain_name = f_domains.readline().strip('\n')
            domain_backup_name = f_init_domains.readline().strip('\n')
            assert domain_name==domain_backup_name, "ERROR : Domain name %s affected by the renaming error" % (domain_backup_name)
        f_domains.close()
        f_init_domains.close()
        log.I("Domains names not affected by the renaming error")
        os.remove("f_domains")

        # Domain renaming error : renaming a domain with an already existent domain name
        log.I("renaming a domain with an already existent domain name")
        log.I("Renaming domain %s to %s" % (self.domain_name,self.new_domain_name) )
        log.I("command [renameDomain]")
        out, err = self.pfw.sendCmd("renameDomain",self.domain_name,self.new_domain_name)
        assert out != "Done", out
        assert err == None, "INFO : command [renameDomain] - Error while renaming domain"
        log.I("command [renameDomain] - renaming error correctly detected")
        # Domains listing using "listDomains" command
        log.I("Creating a domains listing")
        log.I("command [listDomains]")
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "ERROR : command [listDomains] - Error while listing domains"
        log.I("command [listDomains] correctly executed")
        # Saving domains names
        f_domains = open("f_domains", "w")
        f_domains.write(out)
        f_domains.close()
        log.I("Domains listing created")
        # Checking domains names integrity
        log.I("Checking domains names integrity")
        f_domains = open("f_domains", "r")
        f_init_domains = open("f_init_domains", "r")
        for line in range(domains_nbr):
            domain_name = f_domains.readline().strip('\n')
            domain_backup_name = f_init_domains.readline().strip('\n')
            assert domain_name==domain_backup_name, "ERROR : domain name %s affected by the renaming error" % (domain_backup_name)
        f_domains.close()
        f_init_domains.close()
        log.I("Domains names not affected by the renaming error")
        os.remove("f_domains")
        os.remove("f_init_domains")

    def test_Special_Cases(self):
        """
        Special cases
        -------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - renaming a domain with its own name
            Tested commands :
           ~~~~~~~~~~~~~~~~~
                - [renameDomain] function
                - [createDomain] function
                - [listDomains] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - no error
                - domains names remain unchanged
        """
        log.D(self.test_Special_Cases.__doc__)
        # New domain creation
        # Already created in previous test

        # Initial domains listing using "listDomains" command
        log.I("Creating a domains listing backup")
        log.I("command [listDomains]")
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "ERROR : command [listDomains] - Error while listing domains"
        log.I("command [listDomains] correctly executed")
        # Saving initial domains names
        f_init_domains = open("f_init_domains", "w")
        f_init_domains.write(out)
        f_init_domains.close()
        log.I("Domains listing backup created")

        # Checking domains number
        f_init_domains = open("f_init_domains", "r")
        domains_nbr = 0
        line=f_init_domains.readline()
        while line!="":
            line=f_init_domains.readline()
            domains_nbr+=1
        f_init_domains.close()
        log.I("%s domains names saved" % domains_nbr)

        # Domain renaming error : renaming a domain with its own name
        log.I("renaming a domain with its own name")
        log.I("Renaming domain %s to %s" % (self.domain_name,self.domain_name))
        log.I("command [renameDomain]")
        out, err = self.pfw.sendCmd("renameDomain",self.domain_name,self.domain_name)
        assert out == "Done", out
        assert err == None, "ERROR : command [renameDomain] - Error while renaming domain"
        log.I("command [renameDomain] correctly executed")
        # Domains listing using "listDomains" command
        log.I("Creating a domains listing")
        log.I("command [listDomains]")
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "ERROR : command [listDomains] - Error while listing domains"
        log.I("command [listDomains] correctly executed")
        # Saving domains names
        f_domains = open("f_domains", "w")
        f_domains.write(out)
        f_domains.close()
        log.I("Domains listing created")
        # Checking domains names integrity
        log.I("Checking domains names integrity")
        f_domains = open("f_domains", "r")
        f_init_domains = open("f_init_domains", "r")
        for line in range(domains_nbr):
            domain_name = f_domains.readline().strip('\n')
            domain_backup_name = f_init_domains.readline().strip('\n')
            assert domain_name==domain_backup_name, "ERROR : domain name %s affected by the renaming" % (domain_backup_name)
        f_domains.close()
        f_init_domains.close()
        log.I("Domains names not affected by the renaming")

        os.remove("f_domains")
        os.remove("f_init_domains")