def test_get_lifecycle_execution_create_complete(self):
     self.mock_heat_driver.get_stack.return_value = {
         'id':
         '1',
         'stack_status':
         'CREATE_COMPLETE',
         'outputs': [{
             'output_key': 'outputA',
             'output_value': 'valueA'
         }, {
             'output_key': 'outputB',
             'output_value': 'valueB'
         }]
     }
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     execution = driver.get_lifecycle_execution('Create::1::request123',
                                                self.deployment_location)
     self.assertIsInstance(execution, LifecycleExecution)
     self.assertEqual(execution.request_id, 'Create::1::request123')
     self.assertEqual(execution.status, 'COMPLETE')
     self.assertEqual(execution.failure_details, None)
     self.assertEqual(execution.outputs, {
         'outputA': 'valueA',
         'outputB': 'valueB'
     })
     self.assertEqual(execution.associated_topology, None)
 def test_find_reference_returns_empty_when_not_found(self):
     self.mock_tosca_discover_service.discover.side_effect = NotDiscoveredError(
         'Not found')
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     response = driver.find_reference('test', self.tosca_driver_files,
                                      self.deployment_location)
     self.assertIsInstance(response, FindReferenceResponse)
     self.assertIsNone(response.result)
 def test_get_lifecycle_execution_error_when_not_found(self):
     self.mock_heat_driver.get_stack.side_effect = StackNotFoundError(
         'Not found')
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     with self.assertRaises(InfrastructureNotFoundError) as context:
         driver.get_lifecycle_execution('Create::1::request123',
                                        self.deployment_location)
     self.assertEqual(str(context.exception), 'Not found')
 def test_find_reference_with_invalid_template_throws_error(self):
     self.mock_tosca_discover_service.discover.side_effect = ToscaValidationError(
         'Validation error')
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     with self.assertRaises(InvalidDriverFilesError) as context:
         driver.find_reference('test', self.tosca_driver_files,
                               self.deployment_location)
     self.assertEqual(str(context.exception), 'Validation error')
 def test_execute_lifecycle_removes_files(self):
     self.mock_heat_driver.create_stack.return_value = '1'
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     result = driver.execute_lifecycle('Create', self.heat_driver_files,
                                       self.system_properties,
                                       self.resource_properties, {},
                                       AssociatedTopology(),
                                       self.deployment_location)
     self.assertFalse(os.path.exists(self.heat_driver_files.root_path))
 def test_delete_infrastructure_stack_not_found(self):
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     self.mock_heat_driver.delete_stack.side_effect = StackNotFoundError(
         'Not found')
     result = driver.execute_lifecycle('Delete', self.heat_driver_files,
                                       self.system_properties,
                                       self.resource_properties, {},
                                       self.created_associated_topology,
                                       self.deployment_location)
     self.assert_request_id(result.request_id, 'Delete', '1')
 def test_get_lifecycle_executions_requests_stack(self):
     self.mock_heat_driver.get_stack.return_value = {
         'id': '1',
         'stack_status': 'CREATE_IN_PROGRESS'
     }
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     execution = driver.get_lifecycle_execution('Create::1::request123',
                                                self.deployment_location)
     self.mock_location_translator.from_deployment_location.assert_called_once_with(
         self.deployment_location)
     self.mock_heat_driver.get_stack.assert_called_once_with('1')
 def test_execute_lifecycle_on_unsupported_lifecycle_raises_error(self):
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     with self.assertRaises(InvalidRequestError) as context:
         driver.execute_lifecycle('Start', self.heat_driver_files,
                                  self.system_properties,
                                  self.resource_properties, {},
                                  self.created_associated_topology,
                                  self.deployment_location)
     self.assertEqual(
         str(context.exception),
         'Openstack driver only supports Create and Delete transitions, not Start'
     )
 def test_delete_infrastructure(self):
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     result = driver.execute_lifecycle('Delete', self.heat_driver_files,
                                       self.system_properties,
                                       self.resource_properties, {},
                                       self.created_associated_topology,
                                       self.deployment_location)
     self.assertIsInstance(result, LifecycleExecuteResponse)
     self.assert_request_id(result.request_id, 'Delete', '1')
     self.mock_location_translator.from_deployment_location.assert_called_once_with(
         self.deployment_location)
     self.mock_heat_driver.delete_stack.assert_called_once_with('1')
 def test_get_lifecycle_execution_for_delete_stack_not_found(self):
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     self.mock_heat_driver.get_stack.side_effect = StackNotFoundError(
         'Not found')
     execution = driver.get_lifecycle_execution('Delete::1::request123',
                                                self.deployment_location)
     self.assertIsInstance(execution, LifecycleExecution)
     self.assertEqual(execution.request_id, 'Delete::1::request123')
     self.assertEqual(execution.status, 'COMPLETE')
     self.assertEqual(execution.failure_details, None)
     self.assertEqual(execution.outputs, None)
     self.assertEqual(execution.associated_topology, None)
 def test_create_infrastructure_with_invalid_tosca_template_throws_error(
         self):
     self.mock_heat_translator.generate_heat_template.side_effect = ToscaValidationError(
         'Validation error')
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     with self.assertRaises(InvalidDriverFilesError) as context:
         driver.execute_lifecycle('Create', self.tosca_driver_files,
                                  self.system_properties,
                                  self.resource_properties,
                                  {'template-type': 'TOSCA'},
                                  AssociatedTopology(),
                                  self.deployment_location)
     self.assertEqual(str(context.exception), 'Validation error')
Пример #12
0
 def setupResourceDriver(self):
     driver = ResourceDriverHandler(
         OpenstackDeploymentLocationTranslator(),
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=None,
         tosca_discovery_service=None,
         adopt_config=self.adopt_properties)
     return driver
 def test_create_infrastructure_with_invalid_template_type_throws_error(
         self):
     request_properties = {'template-type': 'YAML'}
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     with self.assertRaises(InvalidDriverFilesError) as context:
         driver.execute_lifecycle('Create', self.tosca_driver_files,
                                  self.system_properties,
                                  self.resource_properties,
                                  request_properties, AssociatedTopology(),
                                  self.deployment_location)
     self.assertEqual(
         str(context.exception),
         'Cannot create using template of type \'YAML\'. Must be one of: [\'TOSCA\', \'HEAT\']'
     )
 def test_get_lifecycle_execution_delete_in_progress(self):
     self.mock_heat_driver.get_stack.return_value = {
         'id': '1',
         'stack_status': 'DELETE_IN_PROGRESS'
     }
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     execution = driver.get_lifecycle_execution('Delete::1::request123',
                                                self.deployment_location)
     self.assertIsInstance(execution, LifecycleExecution)
     self.assertEqual(execution.request_id, 'Delete::1::request123')
     self.assertEqual(execution.status, 'IN_PROGRESS')
     self.assertEqual(execution.failure_details, None)
     self.assertEqual(execution.outputs, None)
     self.assertEqual(execution.associated_topology, None)
 def test_create_infrastructure_uses_stack_name_creator(
         self, mock_stack_name_creator):
     self.mock_heat_driver.create_stack.return_value = '1'
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     result = driver.execute_lifecycle('Create', self.heat_driver_files,
                                       self.system_properties,
                                       self.resource_properties, {},
                                       AssociatedTopology(),
                                       self.deployment_location)
     mock_stack_name_creator_inst = mock_stack_name_creator.return_value
     mock_stack_name_creator_inst.create.assert_called_once_with(
         '123', 'TestResource')
     self.mock_heat_driver.create_stack.assert_called_once_with(
         mock_stack_name_creator_inst.create.return_value,
         self.heat_template, {'propA': 'valueA'})
 def test_create_infrastructure_with_not_found_stack_id(self):
     self.mock_heat_driver.get_stack.side_effect = StackNotFoundError(
         'Existing stack not found')
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     self.resource_properties['stack_id'] = {
         'type': 'string',
         'value': 'MY_STACK_ID'
     }
     with self.assertRaises(InfrastructureNotFoundError) as context:
         driver.execute_lifecycle('Create', self.heat_driver_files,
                                  self.system_properties,
                                  self.resource_properties, {},
                                  AssociatedTopology(),
                                  self.deployment_location)
     self.assertEqual(str(context.exception), 'Existing stack not found')
 def test_create_infrastructure(self):
     self.mock_heat_driver.create_stack.return_value = '1'
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     result = driver.execute_lifecycle('Create', self.heat_driver_files,
                                       self.system_properties,
                                       self.resource_properties, {},
                                       AssociatedTopology(),
                                       self.deployment_location)
     self.assertIsInstance(result, LifecycleExecuteResponse)
     self.assert_request_id(result.request_id, 'Create', '1')
     self.assert_internal_resource(result.associated_topology, '1')
     self.mock_location_translator.from_deployment_location.assert_called_once_with(
         self.deployment_location)
     self.mock_heat_driver.create_stack.assert_called_once_with(
         ANY, self.heat_template, {'propA': 'valueA'})
 def test_find_reference(self):
     self.mock_tosca_discover_service.discover.return_value = DiscoveryResult(
         '1', {'test': '1'})
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     response = driver.find_reference('test', self.tosca_driver_files,
                                      self.deployment_location)
     self.assertIsInstance(response, FindReferenceResponse)
     self.assertIsNotNone(response.result)
     self.assertIsInstance(response.result, FindReferenceResult)
     self.assertEqual(response.result.associated_topology, None)
     self.assertEqual(response.result.outputs, {'test': '1'})
     self.mock_location_translator.from_deployment_location.assert_called_once_with(
         self.deployment_location)
     self.mock_tosca_discover_service.discover.assert_called_once_with(
         self.discover_template, self.mock_location_translator.
         from_deployment_location.return_value, {'instance_name': 'test'})
 def test_get_lifecycle_execution_delete_failed_with_no_reason(self):
     self.mock_heat_driver.get_stack.return_value = {
         'id': '1',
         'stack_status': 'DELETE_FAILED'
     }
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     execution = driver.get_lifecycle_execution('Delete::1::request123',
                                                self.deployment_location)
     self.assertIsInstance(execution, LifecycleExecution)
     self.assertEqual(execution.request_id, 'Delete::1::request123')
     self.assertEqual(execution.status, 'FAILED')
     self.assertEqual(execution.failure_details.failure_code,
                      'INFRASTRUCTURE_ERROR')
     self.assertEqual(execution.failure_details.description, None)
     self.assertEqual(execution.outputs, None)
     self.assertEqual(execution.associated_topology, None)
 def test_create_infrastructure_uses_system_prop(self):
     self.mock_heat_input_utils.filter_used_properties.return_value = {
         'system_resourceId': '123'
     }
     self.mock_heat_driver.create_stack.return_value = '1'
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     result = driver.execute_lifecycle('Create', self.heat_driver_files,
                                       self.system_properties,
                                       self.resource_properties, {},
                                       AssociatedTopology(),
                                       self.deployment_location)
     self.mock_heat_input_utils.filter_used_properties.assert_called_once_with(
         self.heat_template,
         PropValueMap({
             'propA': {
                 'type': 'string',
                 'value': 'valueA'
             },
             'propB': {
                 'type': 'string',
                 'value': 'valueB'
             },
             'system_resourceId': {
                 'type': 'string',
                 'value': '123'
             },
             'system_resourceName': {
                 'type': 'string',
                 'value': 'TestResource'
             }
         }))
     self.mock_heat_driver.create_stack.assert_called_once_with(
         ANY, self.heat_template, {'system_resourceId': '123'})
 def test_create_infrastructure_with_stack_id_input(self):
     driver = ResourceDriverHandler(
         self.mock_location_translator,
         resource_driver_config=self.resource_driver_config,
         heat_translator_service=self.mock_heat_translator,
         tosca_discovery_service=self.mock_tosca_discover_service)
     self.resource_properties['stack_id'] = {
         'type': 'string',
         'value': 'MY_STACK_ID'
     }
     result = driver.execute_lifecycle('Create', self.heat_driver_files,
                                       self.system_properties,
                                       self.resource_properties, {},
                                       AssociatedTopology(),
                                       self.deployment_location)
     self.assertIsInstance(result, LifecycleExecuteResponse)
     self.assert_request_id(result.request_id, 'Create', 'MY_STACK_ID')
     self.assert_internal_resource(result.associated_topology,
                                   'MY_STACK_ID')
     self.mock_heat_translator.generate_heat_template.assert_not_called()
     self.mock_heat_driver.create_stack.assert_not_called()
     self.mock_location_translator.from_deployment_location.assert_called_once_with(
         self.deployment_location)
     self.mock_heat_driver.get_stack.assert_called_once_with('MY_STACK_ID')