Browse Source

Tech dept: fix comments from previous commit with new tests

Change-Id: Iba1c3885063860f8442aae759805db8bf8ec4083
changes/43/362043/2
Anastasia Kuznetsova 2 years ago
parent
commit
fd00e5d286
3 changed files with 24 additions and 22 deletions
  1. 23
    18
      tests/base.py
  2. 1
    1
      tests/test_cicd_apps_flow.py
  3. 0
    3
      tox.ini

+ 23
- 18
tests/base.py View File

@@ -31,7 +31,7 @@ import muranoclient.common.exceptions as exceptions
31 31
 
32 32
 import clients
33 33
 
34
-ARTIFACTS_DIR = os.environ.get('ARTIFACTS_DIR', 'logs')
34
+ARTIFACTS_DIR = os.environ.get('ARTIFACTS_DIR', 'artifacts')
35 35
 
36 36
 LOG = logging.getLogger(__name__)
37 37
 LOG.setLevel(logging.DEBUG)
@@ -60,6 +60,8 @@ def str2bool(name, default):
60 60
     value = os.environ.get(name, '')
61 61
     return _boolean_states.get(value.lower(), default)
62 62
 
63
+TIMEOUT_DELAY = 30
64
+
63 65
 
64 66
 class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
65 67
 
@@ -273,7 +275,6 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
273 275
         fips = self.get_services_fips(environment)
274 276
         logs_dir = "{0}/{1}".format(ARTIFACTS_DIR, environment.name)
275 277
         os.makedirs(logs_dir)
276
-        self.files.append(logs_dir)
277 278
         for service, fip in fips.iteritems():
278 279
             try:
279 280
                 ssh = paramiko.SSHClient()
@@ -312,7 +313,7 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
312 313
                     'Environment has incorrect status "{0}"'.format(status)
313 314
                 )
314 315
 
315
-            time.sleep(30)
316
+            time.sleep(TIMEOUT_DELAY)
316 317
         LOG.debug('Environment "{0}" is ready'.format(self.get_env(env).name))
317 318
         return self.get_env(env).manager.get(env.id)
318 319
 
@@ -526,7 +527,7 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
526 527
         return patch['number']
527 528
 
528 529
     def merge_commit(self, gerrit_ip, gerrit_host, project, commit_msg):
529
-        changeid = self.get_last_open_patch(
530
+        patch_num = self.get_last_open_patch(
530 531
             gerrit_ip=gerrit_ip,
531 532
             gerrit_host=gerrit_host,
532 533
             project=project,
@@ -536,7 +537,7 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
536 537
         cmd = (
537 538
             'gerrit review --project {project} --verified +2 '
538 539
             '--code-review +2 --label Workflow=+1 '
539
-            '--submit {id},1'.format(project=project, id=changeid)
540
+            '--submit {id},1'.format(project=project, id=patch_num)
540 541
         )
541 542
         cmd = self._gerrit_cmd(gerrit_host, cmd)
542 543
 
@@ -568,37 +569,41 @@ class MuranoTestsBase(testtools.TestCase, clients.ClientsBase):
568 569
             cmd=cmd
569 570
         )
570 571
 
571
-    def get_jenkins_jobs(self, ip):
572
-        server = jenkins.Jenkins('http://{0}:8080'.format(ip))
573
-
574
-        return [job['name'] for job in server.get_all_jobs()]
575
-
576 572
     def wait_for(self, func, expected, debug_msg, fail_msg, timeout, **kwargs):
577
-        LOG.debug(debug_msg)
578
-        start_time = time.time()
579
-
580
-        current = func(**kwargs)
581
-
582 573
         def check(exp, cur):
583 574
             if isinstance(cur, list) or isinstance(cur, str):
584 575
                 return exp not in cur
585 576
             else:
586 577
                 return exp != cur
587 578
 
579
+        LOG.debug(debug_msg)
580
+        start_time = time.time()
581
+
582
+        current = func(**kwargs)
583
+
588 584
         while check(expected, current):
589 585
             current = func(**kwargs)
590 586
 
591 587
             if time.time() - start_time > timeout:
592 588
                 self.fail("Time is out. {0}".format(fail_msg))
593
-            time.sleep(30)
589
+            time.sleep(TIMEOUT_DELAY)
594 590
         LOG.debug('Expected result has been achieved.')
595 591
 
596
-    def get_last_build_number(self, ip, user, password, job_name, build_type):
597
-        server = jenkins.Jenkins(
592
+    @staticmethod
593
+    def _connect_jenkins_server(ip, user=None, password=None):
594
+        return jenkins.Jenkins(
598 595
             'http://{0}:8080'.format(ip),
599 596
             username=user,
600 597
             password=password
601 598
         )
599
+
600
+    def get_jenkins_jobs(self, ip):
601
+        server = self._connect_jenkins_server(ip)
602
+
603
+        return [job['name'] for job in server.get_all_jobs()]
604
+
605
+    def get_last_build_number(self, ip, user, password, job_name, build_type):
606
+        server = self._connect_jenkins_server(ip, user, password)
602 607
         # If there are no builds of desired type get_job_info returns None and
603 608
         # it is not possible to get number, in this case this function returns
604 609
         # None too and it means that there are no builds yet

+ 1
- 1
tests/test_cicd_apps_flow.py View File

@@ -210,7 +210,7 @@ class MuranoCiCdFlowTest(base.MuranoTestsBase):
210 210
             new_job
211 211
         )
212 212
 
213
-        # Making commit to project-config
213
+        # Make commit to project-config
214 214
 
215 215
         self.make_commit(
216 216
             repo=project_config_location,

+ 0
- 3
tox.ini View File

@@ -22,12 +22,9 @@ distribute = false
22 22
 commands = {posargs:}
23 23
 
24 24
 [testenv:deploy_cicd_apps]
25
-# FIXME!
26 25
 commands = python -m unittest tests.test_cicd_apps.MuranoCiCdTest.test_deploy_cicd
27
-#commands = python setup.py testr --testr-args='{posargs}'
28 26
 
29 27
 [testenv:run_cicd_flow]
30
-# FIXME!
31 28
 commands = python -m unittest tests.test_cicd_apps_flow.MuranoCiCdFlowTest.test_run_cicd_flow
32 29
 
33 30
 [testenv:hacking]

Loading…
Cancel
Save