def __init__(self, machine_type: str, site_name: str): self._configuration = getattr(Configuration(), site_name) self.cloud_stack_client = CloudStack( end_point=self._configuration.end_point, api_key=self._configuration.api_key, api_secret=self._configuration.api_secret, event_loop=runtime._meta_runner.runners[asyncio].event_loop, ) self._machine_type = machine_type self._site_name = site_name key_translator = StaticMapping( remote_resource_uuid="id", drone_uuid="name", resource_status="state" ) translator_functions = StaticMapping( created=lambda date: datetime.strptime(date, "%Y-%m-%dT%H:%M:%S%z"), updated=lambda date: datetime.strptime(date, "%Y-%m-%dT%H:%M:%S%z"), state=lambda x, translator=StaticMapping( Present=ResourceStatus.Booting, Running=ResourceStatus.Running, Stopped=ResourceStatus.Stopped, Expunged=ResourceStatus.Deleted, Destroyed=ResourceStatus.Deleted, ): translator[x], ) self.handle_response = partial( self.handle_response, key_translator=key_translator, translator_functions=translator_functions, )
def __init__(self, machine_type: str, site_name: str): self._machine_type = machine_type self._site_name = site_name auth = AuthPassword( auth_url=self.configuration.auth_url, username=self.configuration.username, password=self.configuration.password, project_name=self.configuration.project_name, user_domain_name=self.configuration.user_domain_name, project_domain_name=self.configuration.project_domain_name, ) self.nova = NovaClient(session=auth) key_translator = StaticMapping(remote_resource_uuid="id", drone_uuid="name", resource_status="status") translator_functions = StaticMapping( created=lambda date: datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ"), updated=lambda date: datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ"), status=lambda x, translator=StaticMapping( BUILD=ResourceStatus.Booting, ACTIVE=ResourceStatus.Running, SHUTOFF=ResourceStatus.Stopped, ERROR=ResourceStatus.Error, ): translator[x], ) self.handle_response = partial( self.handle_response, key_translator=key_translator, translator_functions=translator_functions, )
class TestStaticMapping(TestCase): def setUp(self): self.test_data = {"testA": 123, "testB": "Random String"} self.static_map = StaticMapping(**self.test_data) def test_len_static_mapping(self): self.assertEqual(len(self.static_map), len(self.test_data)) def test_get_item_static_mapping(self): self.assertEqual(self.static_map.get("testA"), self.test_data.get("testA")) self.assertEqual(self.static_map["testB"], self.test_data["testB"]) def test_iter_static_mapping(self): static_map = StaticMapping(**self.test_data) for key, value in static_map.items(): self.assertEqual(value, self.test_data.get(key)) def test_modify_static_mapping(self): with self.assertRaises(TypeError): self.static_map["testB"] = 456 with self.assertRaises(TypeError): self.static_map["testC"] = 456
class TestStaticMapping(TestCase): def setUp(self): self.test_data = {'testA': 123, 'testB': 'Random String'} self.static_map = StaticMapping(**self.test_data) def test_len_static_mapping(self): self.assertEqual(len(self.static_map), len(self.test_data)) def test_get_item_static_mapping(self): self.assertEqual(self.static_map.get('testA'), self.test_data.get('testA')) self.assertEqual(self.static_map['testB'], self.test_data['testB']) def test_iter_static_mapping(self): static_map = StaticMapping(**self.test_data) for key, value in static_map.items(): self.assertEqual(value, self.test_data.get(key)) def test_modify_static_mapping(self): with self.assertRaises(TypeError): self.static_map['testB'] = 456 with self.assertRaises(TypeError): self.static_map['testC'] = 456
def setUp(self): self.test_data = {"testA": 123, "testB": "Random String"} self.static_map = StaticMapping(**self.test_data)
def test_iter_static_mapping(self): static_map = StaticMapping(**self.test_data) for key, value in static_map.items(): self.assertEqual(value, self.test_data.get(key))
def setUp(self): self.test_data = {'testA': 123, 'testB': 'Random String'} self.static_map = StaticMapping(**self.test_data)