summaryrefslogtreecommitdiffstats
path: root/test/functional-tests/PfwTestCase/Domains/tDomain_creation_deletion.py
blob: 039830df062d5ea6f2076347e9700fd3a7575d83 (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
338
339
340
341
342
343
344
# -*-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.

"""
Creation, renaming and deletion configuration testcases

List of tested functions :
--------------------------
    - [createDomain]  function
    - [deleteDomain] function

Test cases :
------------
    - Testing nominal cases
    - Testing domain creation error
    - Testing domain deletion error
"""
import os
from Util.PfwUnitTestLib import PfwTestCase
from Util import ACTLogging
log=ACTLogging.Logger()

# Test of Domains - Basic operations (creations/deletions)
class TestCases(PfwTestCase):
    def setUp(self):
        self.pfw.sendCmd("setTuningMode", "on")
        self.new_domains_number = 4
        self.new_domain_name = "Domain"

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

    def test_Domain_Creation_Error(self):
        """
        Testing domain creation error
        -----------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Create an already existent domain
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [createDomain] function
                - [listDomains] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - Error detected when creating an already existent domain
                - No domains list update
        """
        log.D(self.test_Domain_Creation_Error.__doc__)
        # New domain creation
        log.I("New domain creation")
        log.I("command [createDomain]")
        domain_name = 'Test_Domain'
        out, err = self.pfw.sendCmd("createDomain",domain_name, "")
        assert out == "Done", out
        assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (domain_name)
        log.I("command [createDomain] correctly executed")

        # Domains listing using "listDomains" command
        log.I("Current 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")

        # Domains listing backup
        f_Domains_Backup = open("f_Domains_Backup", "w")
        f_Domains_Backup.write(out)
        f_Domains_Backup.close()
        f_Domains_Backup = open("f_Domains_Backup", "r")
        domains_nbr_init = 0
        line=f_Domains_Backup.readline()
        while line!="":
            line=f_Domains_Backup.readline()
            domains_nbr_init+=1
        f_Domains_Backup.close()
        log.I("Actual domains number : %s" % domains_nbr_init)

        # Trying to add an existent domain name
        log.I("Adding an already existent domain name")
        log.I("command [createDomain]")
        domain_name = 'Test_Domain'
        out, err = self.pfw.sendCmd("createDomain",domain_name, "")
        assert out != "Done", "ERROR : command [createDomain] - Error not detected when creating an already existent domain"
        assert err == None, err
        log.I("command [createDomain] - error correctly detected")

        # Checking domains list integrity
        log.I("Checking domains listing integrity after domain creation error")
        ## Domains listing using "listDomains" command
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "ERROR : command [listDomains] - Error while listing domains"
        f_Domains = open("f_Domains", "w")
        f_Domains.write(out)
        f_Domains.close()
        ## Domains listing integrity check
        f_Domains = open("f_Domains", "r")
        domains_nbr = 0
        line=f_Domains.readline()
        while line!="":
            line=f_Domains.readline()
            domains_nbr+=1
        f_Domains.close()
        assert domains_nbr == domains_nbr_init, "ERROR : Domains number error, expected %s, found %s" % (domains_nbr_init,domains_nbr)
        log.I("Test OK - Domains number not updated")
        f_Domains = open("f_Domains", "r")
        f_Domains_Backup = open("f_Domains_Backup", "r")
        for line in range(domains_nbr):
            domain_backup_name = f_Domains_Backup.readline().strip('\n'),
            domain_name = f_Domains.readline().strip('\n'),
            assert domain_backup_name==domain_name, "ERROR : Error while reading domain %s" % (domain_backup_name)
        log.I("Test OK - Domains listing not affected by domain creation error")

        # Closing and deleting temp files
        f_Domains_Backup.close()
        f_Domains.close()
        os.remove("f_Domains_Backup")
        os.remove("f_Domains")

    def test_Domain_Deletion_Error(self):
        """
        Testing domain deletion error
        -----------------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Delete a non existent domain
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [deleteDomain] function
                - [listDomains] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - Error detected when deleting a non-existent domain
                - No domains list update
        """
        log.D(self.test_Domain_Deletion_Error.__doc__)
        # Domains listing using "listDomains" command
        log.I("Current 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")

        # Domains listing backup
        f_Domains_Backup = open("f_Domains_Backup", "w")
        f_Domains_Backup.write(out)
        f_Domains_Backup.close()
        f_Domains_Backup = open("f_Domains_Backup", "r")
        domains_nbr_init = 0
        line=f_Domains_Backup.readline()
        while line!="":
            line=f_Domains_Backup.readline()
            domains_nbr_init+=1
        f_Domains_Backup.close()
        log.I("Actual domains number : %s" % domains_nbr_init)

        # Trying to delete a non-existent domain name
        log.I("Deleting a non-existent domain name")
        log.I("command [deleteDomain]")
        domain_name = 'Wrong_Domain_Name'
        out, err = self.pfw.sendCmd("deleteDomain",domain_name, "")
        assert out != "Done", "ERROR : command [deleteDomain] - Error not detected when deleting a non-existent domain"
        assert err == None, err
        log.I("command [deleteDomain] - error correctly detected")

        # Checking domains list integrity
        log.I("Checking domains listing integrity after domain deletion error")
        ## Domains listing using "listDomains" command
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "ERROR : command [listDomains] - Error while listing domains"
        f_Domains = open("f_Domains", "w")
        f_Domains.write(out)
        f_Domains.close()
        ## Domains listing integrity check
        f_Domains = open("f_Domains", "r")
        domains_nbr = 0
        line=f_Domains.readline()
        while line!="":
            line=f_Domains.readline()
            domains_nbr+=1
        f_Domains.close()
        assert domains_nbr == domains_nbr_init, "ERROR : Domains number error, expected %s, found %s" % (domains_nbr_init,domains_nbr)
        log.I("Test OK - Domains number not updated")
        f_Domains = open("f_Domains", "r")
        f_Domains_Backup = open("f_Domains_Backup", "r")
        for line in range(domains_nbr):
            domain_backup_name = f_Domains_Backup.readline().strip('\n'),
            domain_name = f_Domains.readline().strip('\n'),
            assert domain_backup_name==domain_name, "Error while reading domain %s" % (domain_backup_name)
        log.I("Test OK - Domains listing not affected by domain deletion error")

        # Closing and deleting temp files
        f_Domains_Backup.close()
        f_Domains.close()
        os.remove("f_Domains_Backup")
        os.remove("f_Domains")

    def test_Nominal_Case(self):
        """
        Testing nominal cases
        ---------------------
            Test case description :
            ~~~~~~~~~~~~~~~~~~~~~~~
                - Create X new domains
                - Delete X domains
            Tested commands :
            ~~~~~~~~~~~~~~~~~
                - [createDomain] function
                - [deleteDomain] function
                - [listDomains] function
            Expected result :
            ~~~~~~~~~~~~~~~~~
                - X new domains created
                - X domains deleted
        """
        log.D(self.test_Nominal_Case.__doc__)
        # Initial domains listing using "listDomains" command
        log.I("Initial 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")

        # Initial domains number count
        f_init_domains = open("f_init_domains", "w")
        f_init_domains.write(out)
        f_init_domains.close()
        init_domains_nbr = 0
        f_init_domains = open("f_init_domains", "r")
        line=f_init_domains.readline()
        while line!="":
            line=f_init_domains.readline()
            init_domains_nbr+=1
        f_init_domains.close()
        log.I("Initial domains number : %s" % (init_domains_nbr))

        # New domains creation
        log.I("New domains creation")
        log.I("PFW command : [createDomain]")
        for index in range (self.new_domains_number):
            domain_name = "".join([self.new_domain_name, "_", str(index+init_domains_nbr)])
            out, err = self.pfw.sendCmd("createDomain",domain_name, "")
            assert out == "Done", "ERROR : %s" % (out)
            assert err == None, "ERROR : command [createDomain] - Error while creating domain %s" % (domain_name)
        log.I("command [createDomain] correctly executed")

        # New domain creation check
        log.I("New domains creation check :")
        log.I("command [listDomains]")
        out, err = self.pfw.sendCmd("listDomains","","")
        assert err == None, "ERROR : command [listDomains] - Error while listing new domains"
        log.I("command [listDomains] correctly executed")

        # Working on a temporary files to record domains listing
        tempfile = open("tempfile", "w")
        tempfile.write(out)
        tempfile.close()

        # Checking last added entries in the listing
        tempfile = open("tempfile", "r")
        domains_nbr = 0
        line=tempfile.readline()
        while line!="":
            line=tempfile.readline()
            domains_nbr+=1
        tempfile.close()
        log.I("New domains conformity check")
        tempfile = open("tempfile", "r")
        for line in range(domains_nbr):
            if (line >= (domains_nbr - self.new_domains_number)):
                domain_name = "".join([self.new_domain_name,"_",str(line)]),
                domain_created = tempfile.readline().strip('\n'),
                assert domain_name==domain_created, "ERROR : Error while creating domain %s %s" % (domain_created, domain_name)
            else:
                domain_created = tempfile.readline()
        log.I("New domains conform to expected values")
        created_domains_number = domains_nbr - init_domains_nbr
        log.I("%s new domains created" % created_domains_number)
        tempfile.close()
        os.remove("tempfile")

        # New domains deletion
        log.I("New domains deletion")
        log.I("command [deleteDomain]")
        for index in range (self.new_domains_number):
            domain_name = "".join([self.new_domain_name, "_", str(index+init_domains_nbr)])
            out, err = self.pfw.sendCmd("deleteDomain",domain_name, "")
            assert out == "Done", "ERROR : %s" % (out)
            assert err == None, "ERROR : command [deleteDomain] - Error while deleting domain %s" % (domain_name)
        log.I("command [deleteDomain] correctly executed")

        # New domains deletion check
        f_init_domains = open("f_init_domains", "r")
        tempfile = open("tempfile", "w")
        log.I("New domains deletion check :")
        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")
        tempfile.write(out)
        tempfile.close()
        tempfile = open("tempfile", "r")
        line=tempfile.readline()
        line_init=f_init_domains.readline()
        while line!="":
            line=tempfile.readline()
            line_init=f_init_domains.readline()
            assert line == line_init, "ERROR : Domain deletion error"
        if line=="":
            assert line_init == "", "ERROR : Wrong domains deletion number"
            log.I("Deletion completed - %s domains deleted" % created_domains_number)

        # Temporary files deletion
        tempfile.close()
        f_init_domains.close()
        os.remove("tempfile")
        os.remove("f_init_domains")