Revision c2f037ff snf-tools/synnefo_tools/burnin/common.py

b/snf-tools/synnefo_tools/burnin/common.py
63 63
MB = 2**20
64 64
GB = 2**30
65 65

  
66
QADD = 1
67
QREMOVE = -1
68

  
69
QDISK = "cyclades.disk"
70
QVM = "cyclades.vm"
71
QPITHOS = "pithos.diskspace"
72
QRAM = "cyclades.ram"
73
QIP = "cyclades.floating_ip"
74
QCPU = "cyclades.cpu"
75
QNET = "cyclades.network.private"
76

  
66 77

  
67 78
# --------------------------------------------------------------------
68 79
# BurninTestResult class
......
217 228
    failfast = None
218 229

  
219 230
    quotas = Proper(value=None)
231
    uuid = Proper(value=None)
220 232

  
221 233
    @classmethod
222 234
    def setUpClass(cls):  # noqa
......
288 300
    def error(self, msg, *args):
289 301
        """Pass the section value to logger"""
290 302
        logger.error(self.suite_name, msg, *args)
303
        self.fail(msg % args)
291 304

  
292 305
    # ----------------------------------
293 306
    # Helper functions that every testsuite may need
294 307
    def _get_uuid(self):
295 308
        """Get our uuid"""
296
        authenticate = self.clients.astakos.authenticate()
297
        uuid = authenticate['access']['user']['id']
298
        self.info("User's uuid is %s", uuid)
299
        return uuid
309
        if self.uuid is None:
310
            authenticate = self.clients.astakos.authenticate()
311
            self.uuid = authenticate['access']['user']['id']
312
            self.info("User's uuid is %s", self.uuid)
313
        return self.uuid
300 314

  
301 315
    def _get_username(self):
302 316
        """Get our User Name"""
......
337 351
                    return su_value
338 352
                else:
339 353
                    self.error("Unrecognized system-user type %s", su_type)
340
                    self.fail("Unrecognized system-user type")
341 354
            except ValueError:
342 355
                msg = "Invalid system-user format: %s. Must be [id|name]:.+"
343 356
                self.warning(msg, self.system_user)
......
412 425
                    [f for f in flavors if str(f['id']) == flv_value]
413 426
            else:
414 427
                self.error("Unrecognized flavor type %s", flv_type)
415
                self.fail("Unrecognized flavor type")
416 428

  
417 429
            # Append and continue
418 430
            ret_flavors.extend(filtered_flvs)
......
483 495
                     i['id'].lower() == img_value.lower()]
484 496
            else:
485 497
                self.error("Unrecognized image type %s", img_type)
486
                self.fail("Unrecognized image type")
487 498

  
488 499
            # Append and continue
489 500
            ret_images.extend(filtered_imgs)
......
536 547

  
537 548
    # pylint: disable=invalid-name
538 549
    # pylint: disable=too-many-arguments
539
    def _check_quotas(self, puuid=None, disk=None, vm=None, diskspace=None,
540
                      ram=None, ip=None, cpu=None, network=None):
550
    def _check_quotas(self, changes):
541 551
        """Check that quotas' changes are consistent
542 552

  
543
        @param puuid: The uuid of the project, quotas are assigned to
553
        @param changes: A dict of the changes that have been made in quotas
544 554

  
545 555
        """
546

  
547
        assert any(v is None for v in
548
                   [disk, vm, diskspace, ram, ip, cpu, network]), \
549
            "_check_quotas require arguments"
556
        if not changes:
557
            return
550 558

  
551 559
        self.info("Check that quotas' changes are consistent")
552 560
        old_quotas = self.quotas
553 561
        new_quotas = self._get_quotas()
554 562
        self.quotas = new_quotas
555 563

  
556
        user_uuid = self._get_uuid()
557
        if puuid is None:
558
            puuid = user_uuid
559

  
560 564
        self.assertListEqual(sorted(old_quotas.keys()),
561 565
                             sorted(new_quotas.keys()))
562
        for project in old_quotas.keys():
563
            # Check Disk usage
564
            project_name = self._get_project_name(project, user_uuid)
565
            self._check_quotas_aux(old_quotas[project], new_quotas[project],
566
                                   project_name, "cyclades.disk",
567
                                   disk, project == puuid)
568
            # Check VM usage
569
            self._check_quotas_aux(old_quotas[project], new_quotas[project],
570
                                   project_name, "cyclades.vm",
571
                                   vm, project == puuid)
572
            # Check DiskSpace usage
573
            self._check_quotas_aux(old_quotas[project], new_quotas[project],
574
                                   project_name, "pithos.diskspace",
575
                                   diskspace, project == puuid)
576
            # Check Ram usage
577
            self._check_quotas_aux(old_quotas[project], new_quotas[project],
578
                                   project_name, "cyclades.ram",
579
                                   ram, project == puuid)
580
            # Check Floating IPs usage
581
            self._check_quotas_aux(old_quotas[project], new_quotas[project],
582
                                   project_name, "cyclades.floating_ip",
583
                                   ip, project == puuid)
584
            # Check CPU usage
585
            self._check_quotas_aux(old_quotas[project], new_quotas[project],
586
                                   project_name, "cyclades.cpu",
587
                                   cpu, project == puuid)
588
            # Check Network usage
589
            self._check_quotas_aux(old_quotas[project], new_quotas[project],
590
                                   project_name, "cyclades.network.private",
591
                                   network, project == puuid)
592

  
593
    def _check_quotas_aux(self, old_quotas, new_quotas,
594
                          project_name, resource, value, check):
595
        """Auxiliary function for _check_quotas"""
596
        old_value = old_quotas[resource]['usage']
597
        new_value = new_quotas[resource]['usage']
598
        if check and value is not None:
599
            assert isinstance(value, int), \
600
                "%s value has to be integer" % resource
601
            old_value += value
602
        self.assertEqual(old_value, new_value,
603
                         "Project %s: %s quotas don't match" %
604
                         (project_name, resource))
566

  
567
        # Take old_quotas and apply changes
568
        for prj, values in changes.items():
569
            self.assertIn(prj, old_quotas.keys())
570
            for q_name, q_mult, q_value, q_unit in values:
571
                if q_unit is None:
572
                    q_unit = 1
573
                q_value = q_mult*int(q_value)*q_unit
574
                assert isinstance(q_value, int), \
575
                    "Project %s: %s value has to be integer" % (prj, q_name)
576
                old_quotas[prj][q_name]['usage'] += q_value
577
                old_quotas[prj][q_name]['project_usage'] += q_value
578

  
579
        self.assertEqual(old_quotas, new_quotas)
605 580

  
606 581
    # ----------------------------------
607 582
    # Projects

Also available in: Unified diff