def test_from_deployment_location_with_certs(self):
     translator = OpenstackDeploymentLocationTranslator()
     certs_dir = os.path.dirname(os.path.abspath(certs.__file__))
     ca_cert_path = os.path.join(certs_dir, 'ca.cert')
     with open(ca_cert_path, 'r') as f:
         ca_cert = f.read()
     client_cert_path = os.path.join(certs_dir, 'client.cert')
     with open(client_cert_path, 'r') as f:
         client_cert = f.read()
     client_key_path = os.path.join(certs_dir, 'client.key')
     with open(client_key_path, 'r') as f:
         client_key = f.read()
     openstack_location = translator.from_deployment_location({'name': 'testdl', 'properties': {
         OS_URL_PROP: 'testip',
         AUTH_API_PROP: 'identity/v3',
         'os_auth_username': '******',
         'os_auth_password': '******',
         'os_auth_domain_id': 'testdomain',
         'os_cacert': ca_cert,
         'os_cert': client_cert, 
         'os_key': client_key
     }})
     self.assertEqual(openstack_location._OpenstackDeploymentLocation__ca_cert, ca_cert)
     self.assertEqual(openstack_location._OpenstackDeploymentLocation__client_cert, client_cert)
     self.assertEqual(openstack_location._OpenstackDeploymentLocation__client_key, client_key)
Esempio n. 2
0
 def test_from_deployment_location_auth_collects_properties_with_prefix(
         self):
     translator = OpenstackDeploymentLocationTranslator()
     openstack_location = translator.from_deployment_location({
         'name': 'testdl',
         'properties': {
             OS_URL_PROP: 'testip',
             AUTH_API_PROP: 'identity/v3',
             'os_auth_username': '******',
             'os_auth_password': '******',
             'os_auth_domain_id': 'testdomain'
         }
     })
     self.assertEqual(
         type(openstack_location._OpenstackDeploymentLocation__auth),
         OpenstackPasswordAuth)
     openstack_auth = openstack_location._OpenstackDeploymentLocation__auth
     self.assertEqual(openstack_auth.auth_api, 'identity/v3')
     self.assertIn('username', openstack_auth.auth_properties)
     self.assertEqual(openstack_auth.auth_properties['username'], 'test')
     self.assertIn('password', openstack_auth.auth_properties)
     self.assertEqual(openstack_auth.auth_properties['password'], 'secret')
     self.assertIn('domain_id', openstack_auth.auth_properties)
     self.assertEqual(openstack_auth.auth_properties['domain_id'],
                      'testdomain')
     self.assertEqual(len(openstack_auth.auth_properties), 3)
 def test_from_deployment_location_auth_api_missing(self):
     translator = OpenstackDeploymentLocationTranslator()
     with self.assertRaises(ValueError) as context:
         translator.from_deployment_location({'name': 'testdl', 'properties': {
             OS_URL_PROP: 'testip'
         }})
     self.assertEqual(str(context.exception), 'Deployment Location must specify a value for property \'{0}\' when auth is enabled'.format(AUTH_API_PROP))
 def test_from_deployment_location_auth_disabled(self):
     translator = OpenstackDeploymentLocationTranslator()
     openstack_location = translator.from_deployment_location({'name': 'testdl', 'properties': {
         OS_URL_PROP: 'testip',
         AUTH_ENABLED_PROP: False
     }})
     self.assertIsNone(openstack_location._OpenstackDeploymentLocation__auth)
 def test_from_deployment_location_auth_enabled_not_a_bool(self):
     translator = OpenstackDeploymentLocationTranslator()
     with self.assertRaises(ValueError) as context:
         translator.from_deployment_location({'name': 'testdl', 'properties': {
             OS_URL_PROP: 'testip',
             AUTH_ENABLED_PROP: 'Truuueee'
         }})
     self.assertEqual(str(context.exception), 'Deployment Location should have a boolean value for property \'{0}\''.format(AUTH_ENABLED_PROP))
Esempio n. 6
0
    def test_from_deployment_location_missing_properties(self):
        translator = OpenstackDeploymentLocationTranslator()

        with self.assertRaises(ValueError) as context:
            translator.from_deployment_location({'name': 'testdl'})
        self.assertEqual(
            str(context.exception),
            'Deployment Location managed by the Openstack VIM Driver must specify a property value for \'{0}\''
            .format(OS_URL_PROP))
Esempio n. 7
0
    def test_from_deployment_location_missing_name(self):
        translator = OpenstackDeploymentLocationTranslator()

        with self.assertRaises(ValueError) as context:
            translator.from_deployment_location(
                {'description': 'dl with no name'})
        self.assertEqual(
            str(context.exception),
            'Deployment Location managed by the Openstack VIM Driver must have a name'
        )
Esempio n. 8
0
def create_app():
    logging.basicConfig(level=logging.INFO)

    app_builder = ignition.build_vim_driver('Openstack VIM Driver')
    app_builder.include_file_config_properties(default_config_path,
                                               required=True)
    app_builder.include_file_config_properties('./ovd_config.yml',
                                               required=False)
    # custom config file e.g. for K8s populated from Helm chart values
    app_builder.include_file_config_properties('/var/ovd/ovd_config.yml',
                                               required=False)
    app_builder.include_environment_config_properties('OVD_CONFIG',
                                                      required=False)
    app_builder.add_service(ToscaParserService)
    app_builder.add_service(ToscaTopologyDiscoveryService,
                            tosca_parser_service=ToscaParserCapability)
    app_builder.add_service(ToscaHeatTranslatorService,
                            tosca_parser_service=ToscaParserCapability)
    app_builder.add_service(
        InfrastructureDriver,
        OpenstackDeploymentLocationTranslator(),
        heat_translator_service=ToscaHeatTranslatorCapability,
        tosca_discovery_service=ToscaTopologyDiscoveryCapability)

    # Custom Property Group, Service and API
    app_builder.add_property_group(OpenstackAdminProperties())
    app_builder.add_api_configurator(OpenstackAdminApiConfigurator())
    app_builder.add_service_configurator(OpenstackAdminServiceConfigurator())

    return app_builder.configure()
Esempio n. 9
0
 def configure(self, configuration, service_register):
     admin_properties = configuration.property_groups.get_property_group(OpenstackAdminProperties)
     if admin_properties.enabled is True:
         logger.debug('Configuring Openstack Admin Services')
         service_register.add_service(ServiceRegistration(OpenstackAdminApiService, service=OpenstackAdminCapability))
         service_register.add_service(ServiceRegistration(OpenstackAdminService, OpenstackDeploymentLocationTranslator()))
     else:
         logger.debug('Disabled: Openstack Admin Services')
Esempio n. 10
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_from_deployment_location_certs_multiline_string(self, mock_keystone_session_init):
     translator = OpenstackDeploymentLocationTranslator()
     certs_dir = os.path.dirname(os.path.abspath(certs.__file__))
     location_path = os.path.join(certs_dir, 'location.yaml')
     with open(location_path, 'r') as f:
         location_dict = yaml.safe_load(f.read())
     location = translator.from_deployment_location(location_dict)
     try:
         location.create_session()
         self.assertTrue(os.path.exists(location._OpenstackDeploymentLocation__ca_cert_path))
         path_to_expected_cacert = os.path.join(certs_dir, 'ca.cert')
         with open(path_to_expected_cacert, 'r') as f:
             expected_cacert = f.read()
         with open(location._OpenstackDeploymentLocation__ca_cert_path, 'r') as f:
             actual_cacert = f.read()
         self.assertEqual(actual_cacert, expected_cacert)
     finally:
         location.close()