def test_run_lifecycle(self): resp = self.lifecycle_driver.execute_lifecycle('install', DirectoryTree('./'), {}, {}, {}, {}, {}) self.assertIsNone(resp)
def test_run_lifecycle_with_kubernetes_inventory(self): # configure so that we can see logging from the code under test stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) try: request_id = uuid.uuid4().hex properties = PropValueMap({ 'hello_world_private_ip': { 'value': '10.220.217.113', 'type': 'string' }, 'ansible_ssh_user': { 'value': 'accanto', 'type': 'string' }, 'ansible_ssh_pass': { 'value': 'accanto', 'type': 'string' }, 'ansible_become_pass': { 'value': 'accanto', 'type': 'string' }, 'bool_prop': { 'value': True, 'type': 'boolean' }, 'int_prop': { 'value': 123, 'type': 'integer' }, 'float_prop': { 'value': 1.2, 'type': 'float' }, 'timestamp_prop': { 'value': '2020-11-23T11:49:33.308703Z', 'type': 'timestamp' }, 'map_prop': { 'value': { 'A': 1, 'B': 'A string' }, 'type': 'map' }, 'list_prop': { 'value': ['a', 'b', 'c'], 'type': 'list' }, 'custom_type_prop': { 'value': { 'name': 'Testing', 'age': 42 }, 'type': 'MyCustomType' } }) system_properties = PropValueMap({ }) dst = self.__copy_directory_tree(str(pathlib.Path(__file__).parent.absolute()) + '/../../resources/ansible') resp = self.ansible_client.run_lifecycle_playbook({ 'lifecycle_name': 'install', 'driver_files': DirectoryTree(dst), 'system_properties': system_properties, 'resource_properties': properties, 'deployment_location': { 'name': 'winterfell', 'type': "Kubernetes", 'properties': PropValueMap({ }) }, 'request_id': request_id }) self.assertLifecycleExecutionEqual(resp, LifecycleExecution(request_id, STATUS_COMPLETE, None, {'msg': "hello there!"})) self.assertFalse(os.path.exists(dst)) finally: logger.removeHandler(stream_handler)
def test_run_lifecycle_with_outputs_of_different_types(self): stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) try: request_id = uuid.uuid4().hex properties = PropValueMap({ 'hello_world_private_ip': { 'value': '10.220.217.113', 'type': 'string' }, 'ansible_ssh_user': { 'value': 'accanto', 'type': 'string' }, 'ansible_ssh_pass': { 'value': 'accanto', 'type': 'string' }, 'ansible_become_pass': { 'value': 'accanto', 'type': 'string' } }) system_properties = PropValueMap({ }) dst = self.__copy_directory_tree(str(pathlib.Path(__file__).parent.absolute()) + '/../../resources/ansible_outputs') resp = self.ansible_client.run_lifecycle_playbook({ 'lifecycle_name': 'install', 'driver_files': DirectoryTree(dst), 'system_properties': system_properties, 'resource_properties': properties, 'deployment_location': { 'name': 'winterfell', 'type': "Kubernetes", 'properties': PropValueMap({ }) }, 'request_id': request_id }) expected_outputs = { 'string_prop': 'Hello', 'int_prop': 1, 'float_prop': 1.2, 'bool_prop': True, 'timestamp_prop': '2020-11-23T11:49:33.308703Z', 'map_prop': { 'A': 'ValueA', 'B': 123 }, 'list_prop': ['A', 'B'], 'custom_type_prop': { 'name': 'Testing', 'age': 42 } } self.assertLifecycleExecutionEqual(resp, LifecycleExecution(request_id, STATUS_COMPLETE, None, expected_outputs)) self.assertFalse(os.path.exists(dst)) finally: logger.removeHandler(stream_handler)
def test_run_lifecycle_return_associated_topology(self): # configure so that we can see logging from the code under test stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) try: request_id = uuid.uuid4().hex properties = PropValueMap({ 'hello_world_private_ip': { 'value': '10.220.217.113', 'type': 'string' }, 'ansible_ssh_user': { 'value': 'accanto', 'type': 'string' }, 'ansible_ssh_pass': { 'value': 'accanto', 'type': 'string' }, 'ansible_become_pass': { 'value': 'accanto', 'type': 'string' } }) system_properties = PropValueMap({ }) dst = self.__copy_directory_tree(str(pathlib.Path(__file__).parent.absolute()) + '/../../resources/ansible_returning_associated_topology_and_outputs') resp = self.ansible_client.run_lifecycle_playbook({ 'lifecycle_name': 'create', 'driver_files': DirectoryTree(dst), 'system_properties': system_properties, 'resource_properties': properties, 'deployment_location': { 'name': 'winterfell', 'type': "Kubernetes", 'properties': PropValueMap({ }) }, 'keep_files': True, 'request_id': request_id }) associated_topology = AssociatedTopology.from_dict({ 'apache1': { 'id': '12345678', 'type': 'Openstack' }, 'apache2': { 'id': '910111213', 'type': 'Openstack' } }) self.assertLifecycleExecutionEqual(resp, LifecycleExecution(request_id, STATUS_COMPLETE, None, {'msg': "Associated topology returned", 'public_ip': "10.21.28.94", 'internal_ip': "10.10.10.42"}, associated_topology)) self.assertTrue(os.path.exists(dst)) finally: logger.removeHandler(stream_handler)
def test_run_lifecycle_with_malformed_associated_topology_in_playbook(self): # configure so that we can see logging from the code under test stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) try: request_id = uuid.uuid4().hex infrastructure_id_1 = uuid.uuid4().hex infrastructure_id_2 = uuid.uuid4().hex infrastructure_osp_type = 'Openstack' infrastructure_k8s_type = 'Kubernetes' properties = PropValueMap({ 'hello_world_private_ip': { 'value': '10.220.217.113', 'type': 'string' }, 'ansible_ssh_user': { 'value': 'accanto', 'type': 'string' }, 'ansible_ssh_pass': { 'value': 'accanto', 'type': 'string' }, 'ansible_become_pass': { 'value': 'accanto', 'type': 'string' } }) system_properties = PropValueMap({ }) associated_topology = AssociatedTopology.from_dict({ 'apache1': { 'id': infrastructure_id_1, 'type': infrastructure_osp_type }, 'apache2': { 'id': infrastructure_id_2, 'type': infrastructure_k8s_type } }) dst = self.__copy_directory_tree(str(pathlib.Path(__file__).parent.absolute()) + '/../../resources/ansible_with_malformed_associated_topology_in_playbook') resp = self.ansible_client.run_lifecycle_playbook({ 'lifecycle_name': 'adopt', 'driver_files': DirectoryTree(dst), 'system_properties': system_properties, 'resource_properties': properties, 'deployment_location': { 'name': 'winterfell', 'type': "Kubernetes", 'properties': PropValueMap({ }) }, 'associated_topology': associated_topology, 'keep_files': True, 'request_id': request_id }) self.assertLifecycleExecutionMatches(resp, LifecycleExecution(request_id, STATUS_FAILED, FailureDetails(FAILURE_CODE_INFRASTRUCTURE_ERROR, "task debug failed: {'msg': \"The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'wrong'"), {})) self.assertTrue(os.path.exists(dst)) finally: logger.removeHandler(stream_handler)
def test_run_lifecycle_with_input_associated_topology(self): # configure so that we can see logging from the code under test stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) try: request_id = uuid.uuid4().hex infrastructure_id_1 = uuid.uuid4().hex infrastructure_id_2 = uuid.uuid4().hex infrastructure_osp_type = 'Openstack' infrastructure_k8s_type = 'Kubernetes' properties = PropValueMap({ 'hello_world_private_ip': { 'value': '10.220.217.113', 'type': 'string' }, 'ansible_ssh_user': { 'value': 'accanto', 'type': 'string' }, 'ansible_ssh_pass': { 'value': 'accanto', 'type': 'string' }, 'ansible_become_pass': { 'value': 'accanto', 'type': 'string' } }) system_properties = PropValueMap({ }) associated_topology = AssociatedTopology.from_dict({ 'apache1': { 'id': infrastructure_id_1, 'type': infrastructure_osp_type }, 'apache2': { 'id': infrastructure_id_2, 'type': infrastructure_k8s_type } }) dst = self.__copy_directory_tree(str(pathlib.Path(__file__).parent.absolute()) + '/../../resources/ansible_input_associated_topology') resp = self.ansible_client.run_lifecycle_playbook({ 'lifecycle_name': 'adopt', 'driver_files': DirectoryTree(dst), 'system_properties': system_properties, 'resource_properties': properties, 'deployment_location': { 'name': 'winterfell', 'type': "Kubernetes", 'properties': PropValueMap({ }) }, 'associated_topology': associated_topology, 'keep_files': True, 'request_id': request_id }) self.assertLifecycleExecutionEqual(resp, LifecycleExecution(request_id, STATUS_COMPLETE, None, {'msg': "hello there!"})) self.assertTrue(os.path.exists(dst)) finally: logger.removeHandler(stream_handler)