def test_get_project(self): project = Project() project.setId(1) project.setName("test_project") self.fsmanager.addProject(project) self.assertEqual(project, self.fsmanager.getProject(1))
def test_add_project(self): project = Project() project.setId(1) project.setName("test_project") prj_share = project.getShare() prj_share.setValue(5) self.fsmanager.addProject(project) self.assertEqual(1, self.fsmanager.projects[1].getId()) self.assertEqual("test_project", self.fsmanager.projects[1].getName()) self.assertEqual([], self.fsmanager.projects[1].getUsers()) self.assertEqual(5, self.fsmanager.projects[1].getShare().getValue())
def test_remove_project(self): project = Project() project.setId(1) project.setName("test_project") self.fsmanager.addProject(project) self.assertIn(1, self.fsmanager.projects) self.fsmanager.removeProject(1) self.assertNotIn(1, self.fsmanager.projects)
def test_add_project_no_share(self): project = Project() project.setId(1) project.setName("test_project") self.fsmanager.addProject(project) self.assertEqual(1, self.fsmanager.projects[1].getId()) self.assertEqual("test_project", self.fsmanager.projects[1].getName()) self.assertEqual([], self.fsmanager.projects[1].getUsers()) self.assertEqual(self.fsmanager.default_share, self.fsmanager.projects[1].getShare().getValue())
def test_calculate_priority_one_user(self): # self.fsmanager.addProject(prj_id=1, prj_name="test") project = Project() project.setId(1) project.setName("test_project") # Define values used for computing the priority age_weight = self.fsmanager.age_weight = 1.0 vcpus_weight = self.fsmanager.vcpus_weight = 2.0 memory_weight = self.fsmanager.memory_weight = 3.0 datetime_start = datetime(year=2000, month=1, day=1, hour=0, minute=0) datetime_stop = datetime(year=2000, month=1, day=1, hour=2, minute=0) minutes = (datetime_stop - datetime_start).seconds / 60 fairshare_cores = 10 fairshare_ram = 50 # Add a user to the project user = User() user.setId(22) user.setName("test_user") priority = user.getPriority() priority.setFairShare('vcpus', fairshare_cores) priority.setFairShare('memory', fairshare_ram) project.addUser(user) self.fsmanager.addProject(project) # Compute the expected priority given the previously defined values expected_priority = int(age_weight * minutes + vcpus_weight * fairshare_cores + memory_weight * fairshare_ram) with patch("synergy_scheduler_manager.fairshare_manager.datetime") \ as datetime_mock: datetime_mock.utcnow.side_effect = (datetime_start, datetime_stop) priority = self.fsmanager.calculatePriority(user_id=22, prj_id=1) self.assertEqual(expected_priority, priority)
def test_info_quota(self): SharedQuota.setSize("vcpus", 20) SharedQuota.setSize("memory", 4096) SharedQuota.enable() self.assertEqual(20, SharedQuota.getSize('vcpus')) self.assertEqual(4096, SharedQuota.getSize('memory')) prj_a = Project() prj_a.setId(1) prj_a.setName("prj_a") prj_b = Project() prj_b.setId(2) prj_b.setName("prj_b") prjDict = {1: prj_a, 2: prj_b} quota = prjDict[1].getQuota() quota.setSize("vcpus", 10, private=True) quota.setSize("memory", 2048, private=True) self.assertEqual(10, quota.getSize('vcpus', private=True)) self.assertEqual(2048, quota.getSize('memory', private=True)) quota.setSize("vcpus", SharedQuota.getSize('vcpus'), private=False) quota.setSize("memory", SharedQuota.getSize('memory'), private=False) self.assertEqual(20, quota.getSize('vcpus', private=False)) self.assertEqual(4096, quota.getSize('memory', private=False)) flavor = Flavor() flavor.setVCPUs(2) flavor.setMemory(512) server = Server() server.setType("ephemeral") server.setId("server_id") server.setFlavor(flavor) self.assertEqual(True, server.isEphemeral()) try: allocated = quota.allocate(server, blocking=False) except Exception as ex: print(ex) self.assertEqual(True, allocated) self.assertEqual(0, quota.getUsage('vcpus', private=True)) self.assertEqual(0, quota.getUsage('memory', private=True)) self.assertEqual(2, quota.getUsage('vcpus', private=False)) self.assertEqual(512, quota.getUsage('memory', private=False)) self.assertEqual(2, SharedQuota.getUsage('vcpus')) self.assertEqual(512, SharedQuota.getUsage('memory')) ns = Notifications(prjDict, None) payload = { "state": "deleted", "deleted_at": "2016-12-09T10:06:10.000000", "terminated_at": "2016-12-09T10:06:10.025305", "instance_type": "m1.tiny", "user_id": "user", "root_gb": "1", "metadata": {}, "instance_id": "server_id", "tenant_id": 1, "memory_mb": 512, "vcpus": 2 } ns.info(ctxt=None, publisher_id=None, event_type="compute.instance.delete.end", payload=payload, metadata=None) quota = prjDict[1].getQuota() self.assertEqual(0, quota.getUsage("vcpus", private=True)) self.assertEqual(0, quota.getUsage("memory", private=True)) self.assertEqual(0, quota.getUsage('vcpus', private=False)) self.assertEqual(0, quota.getUsage('memory', private=False)) self.assertEqual(0, SharedQuota.getUsage('vcpus')) self.assertEqual(0, SharedQuota.getUsage('memory'))
def setUp(self): super(TestWorker, self).setUp() self.nova_manager_mock = MagicMock() self.keystone_manager_mock = MagicMock() db_engine_mock = create_autospec(Engine) project1 = Project() project1.setId("1") project1.setName("test1") project2 = Project() project2.setId("2") project2.setName("test2") projects_list = {'1': project1, '2': project2} self.worker = Worker(name="test", queue=QueueDB("testq", db_engine_mock), projects=projects_list, nova_manager=self.nova_manager_mock, keystone_manager=self.keystone_manager_mock)
def my_side_effect(*args, **kwargs): project1 = Project() project1.setId(1) project1.setName("test_project1") project1.getShare().setValue(5) project2 = Project() project2.setId(2) project2.setName("test_project2") project2.getShare().setValue(55) if args[0] == 1: return project1 elif args[0] == 2: return project2
def test_set_get_Project(self): prj = Project() self.token.setProject(prj) self.assertEqual(0.0, self.token.getProject().getTTL())
def setUp(self): super(TestProject, self).setUp() self.prj = Project()
class TestProject(base.TestCase): def setUp(self): super(TestProject, self).setUp() self.prj = Project() def test_set_get_Data(self): self.assertEqual({}, self.prj.getData()) def test_get_Quota(self): sq = self.prj.getQuota() sq.setSize('memory', 1024, True) sq.setSize('vcpus', 100.00, True) sq.setSize('instances', 10, True) self.assertEqual(1024, sq.getSize('memory')) self.assertEqual(100.0, sq.getSize('vcpus')) self.assertEqual(10, sq.getSize('instances')) def test_get_Share(self): share = self.prj.getShare() self.assertEqual(0.0, share.getValue()) self.assertEqual(0.00, share.getSiblingValue()) self.assertEqual(0.000, share.getNormalizedValue()) def test_set_get_TTL(self): self.prj.setTTL(0.2) self.assertEqual(0.2, self.prj.getTTL()) def test_set_is_Enable(self): self.prj.setEnabled('True') self.assertEqual('True', self.prj.isEnabled()) def test_get_add_User(self): user1 = User() user1.setId('id1') user1.setName('name1') self.prj.addUser(user1) user2 = User() user2.setId('id2') user2.setName('name2') self.prj.addUser(user2) self.assertEqual('id1', self.prj.getUser('id1').getId()) self.assertEqual('name1', self.prj.getUser('id1').getName()) self.assertEqual('id2', self.prj.getUser('id2').getId()) self.assertEqual('name2', self.prj.getUser('id2').getName()) def test_get_Users(self): user = User() user.setId('id1') user.setName('name') self.prj.addUser(user) self.assertEqual('name', self.prj.getUser('id1').getName())
def test_get_projects(self): project1 = Project() project1.setId(1) project1.setName("test1") self.fsmanager.addProject(project1) project2 = Project() project2.setId(2) project2.setName("test2") self.fsmanager.addProject(project2) expected_projects = {1: project1, 2: project2} self.assertEqual(expected_projects, self.fsmanager.getProjects())