예제 #1
0
 def test_discover_full_attribute_support(self):
     self.__configure_mock_neutron_driver_with_network_and_subnets(
         'TestNetwork')
     tosca_template = self.__get_template(
         discover_network_full_attributes_support_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     search_result = search_impl.discover(tosca_template)
     self.mock_neutron_driver.get_network_by_name.assert_called_once_with(
         'TestNetwork')
     self.assertIsInstance(search_result, DiscoveryResult)
     self.assertEqual(search_result.discover_id, 'TestNetwork')
     self.assertEqual(
         search_result.outputs, {
             'ip_version': self.test_subnet_a['ip_version'],
             'cidr': self.test_subnet_a['cidr'],
             'start_ip': self.test_subnet_a['allocation_pools'][0]['start'],
             'end_ip': self.test_subnet_a['allocation_pools'][0]['end'],
             'gateway_ip': self.test_subnet_a['gateway_ip'],
             'network_id': self.test_network['id'],
             'network_name': self.test_network['name'],
             'segmentation_id':
             self.test_network['provider:segmentation_id'],
             'network_type': self.test_network['provider:network_type'],
             'physical_network':
             self.test_network['provider:physical_network'],
             'dhcp_enabled': self.test_subnet_a['enable_dhcp']
         })
예제 #2
0
 def test_discover_non_network_type_fails(self):
     tosca_template = self.__get_template(not_a_network_tosca_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(str(context.exception),
                      'Cannot discover nodes of type: tosca.nodes.Custom')
예제 #3
0
 def test_discover_no_node_templates_fails(self):
     tosca_template = self.__get_template(missing_node_templates_tosca_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'tosca_template features no node_templates, so there is nothing to discover'
     )
예제 #4
0
 def test_discover_not_found_raises_exception(self):
     self.__configure_mock_neutron_driver_with_not_found('TestNetwork')
     tosca_template = self.__get_template(discover_network_tosca_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(NotDiscoveredError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'Cannot find tosca.nodes.network.Network with search value: TestNetwork'
     )
예제 #5
0
 def test_discover_by_multiple_property_fails(self):
     tosca_template = self.__get_template(
         discover_network_with_multiple_properties_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'tosca.nodes.network.Network nodes can only be found with a single \'network_name\' or \'network_id\' property but multiple properties were found on the node template: [\'network_name\', \'ip_version\']'
     )
예제 #6
0
 def test_discover_by_unsupported_property_fails(self):
     tosca_template = self.__get_template(
         discover_network_with_unsupported_property_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'tosca.nodes.network.Network nodes can only be found with a single \'network_name\' or \'network_id\' property but \'ip_version\' was set instead'
     )
예제 #7
0
 def test_discover_network_with_unsupported_property_function_fails(self):
     tosca_template = self.__get_template(
         discover_network_with_unsupported_property_function_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'Resolving function of type \'GetAttribute\' is not supported through discovery'
     )
예제 #8
0
 def test_discover_network(self):
     self.__configure_mock_neutron_driver_with_network('TestNetwork')
     tosca_template = self.__get_template(discover_network_tosca_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     search_result = search_impl.discover(tosca_template)
     self.mock_neutron_driver.get_network_by_name.assert_called_once_with(
         'TestNetwork')
     self.assertIsInstance(search_result, DiscoveryResult)
     self.assertEqual(search_result.discover_id, 'TestNetwork')
     self.assertEqual(search_result.outputs, {})
예제 #9
0
 def test_discover_multiple_nodes_fails(self):
     tosca_template = self.__get_template(
         multiple_node_templates_tosca_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'tosca_template for topology discovery expected to feature only a single node template'
     )
예제 #10
0
 def test_discover_with_get_operation_output_fails(self):
     self.__configure_mock_neutron_driver_with_network('TestNetwork')
     tosca_template = self.__get_template(
         discover_network_with_get_operation_output_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'Resolving output value with function \'GetOperationOutput\' is not supported through discovery'
     )
예제 #11
0
 def ignored_test_discover_with_output_to_other_node_fails(self):
     # Currently not possible as the Tosca Parser validates the output references a known node_template
     # and the NetworkSearchImpl validates that there is only one node_template
     self.__configure_mock_neutron_driver_with_network('TestNetwork')
     tosca_template = self.__get_template(
         discover_network_with_output_to_other_node_file)
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(InvalidDiscoveryToscaError) as context:
         search_impl.discover(tosca_template)
     self.assertEqual(
         str(context.exception),
         'Attributes can only been resolved to the single node_template named \'network\' but output \'network_name}\' references \'other_node\''
     )
예제 #12
0
 def test_discover_without_template_fails(self):
     search_impl = NetworkSearchImpl(self.mock_openstack_location)
     with self.assertRaises(ValueError) as context:
         search_impl.discover(None)
     self.assertEqual(str(context.exception),
                      'Must provide tosca_template parameter')
예제 #13
0
 def test_init_without_location_fails(self):
     with self.assertRaises(ValueError) as context:
         search_impl = NetworkSearchImpl(None)
     self.assertEqual(str(context.exception),
                      'Must provide openstack_location parameter')