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_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))
Beispiel #3
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))
Beispiel #4
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'
        )
Beispiel #5
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_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)
 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_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()