Esempio n. 1
0
    def test_load(self):
        env = environment.Environment()
        env.load({})
        self.assertEqual({}, env.params)
        self.assertEqual({}, env.profile_registry._registry)
        self.assertEqual({}, env.policy_registry._registry)
        self.assertEqual({}, env.trigger_registry._registry)
        self.assertEqual({}, env.driver_registry._registry)

        env_dict = {
            'parameters': {
                'P': 'V'
            },
            'custom_profiles': {
                'C1': 'class1',
            },
            'custom_policies': {
                'C2': 'class2',
            },
            'custom_triggers': {
                'C3': 'class3',
            }

        }
        env.load(env_dict)
        self.assertEqual('V', env.params['P'])
        self.assertEqual('class1', env.get_profile('C1'))
        self.assertEqual('class2', env.get_policy('C2'))
        self.assertEqual('class3', env.get_trigger('C3'))
Esempio n. 2
0
    def test_create_default(self):
        ge = environment.global_env()
        e = environment.Environment()

        reg_prof = e.profile_registry
        reg_plcy = e.policy_registry
        reg_trig = e.trigger_registry
        reg_driv = e.driver_registry

        self.assertEqual({}, e.params)
        self.assertEqual('profiles', reg_prof.registry_name)
        self.assertEqual('policies', reg_plcy.registry_name)
        self.assertEqual('triggers', reg_trig.registry_name)
        self.assertEqual('drivers', reg_driv.registry_name)
        self.assertFalse(reg_prof.is_global)
        self.assertFalse(reg_plcy.is_global)
        self.assertFalse(reg_trig.is_global)
        self.assertFalse(reg_driv.is_global)
        self.assertEqual('profiles', ge.profile_registry.registry_name)
        self.assertEqual('policies', ge.policy_registry.registry_name)
        self.assertEqual('triggers', ge.trigger_registry.registry_name)
        self.assertEqual('drivers', ge.driver_registry.registry_name)
        self.assertEqual(ge.profile_registry, reg_prof.global_registry)
        self.assertEqual(ge.policy_registry, reg_plcy.global_registry)
        self.assertEqual(ge.trigger_registry, reg_trig.global_registry)
        self.assertEqual(ge.driver_registry, reg_driv.global_registry)
Esempio n. 3
0
    def test_empty_environment_dir(self):
        mock_dir = self.patchobject(glob, 'glob', return_value=[])
        env_dir = '/etc/senlin/environments'
        env = environment.Environment()
        env.read_global_environment()

        mock_dir.assert_called_once_with(env_dir + '/*')
Esempio n. 4
0
    def test_create_with_env(self):
        env = {
            'parameters': {
                'p1': 'v1',
                'p2': True,
            },
            'custom_profiles': {
                'PROFILE_FOO': 'some.class',
                'PROFILE_BAR': 'other.class',
            },
            'custom_policies': {
                'POLICY_Alpha': 'package.alpha',
                'POLICY_Beta': 'package.beta',
            },
            'custom_triggers': {
                'TRIGGER_1': 'module.1',
                'TRIGGER_2': 'module.2',
            }
        }

        e = environment.Environment(env=env, is_global=True)

        self.assertEqual('v1', e.params['p1'])
        self.assertEqual(True, e.params['p2'])
        self.assertEqual('some.class', e.get_profile('PROFILE_FOO'))
        self.assertEqual('other.class', e.get_profile('PROFILE_BAR'))
        self.assertEqual('package.alpha', e.get_policy('POLICY_Alpha'))
        self.assertEqual('package.beta', e.get_policy('POLICY_Beta'))
        self.assertEqual('module.1', e.get_trigger('TRIGGER_1'))
        self.assertEqual('module.2', e.get_trigger('TRIGGER_2'))
Esempio n. 5
0
    def test_read_global_environment_oserror(self):
        mock_dir = self.patchobject(glob, 'glob')
        mock_dir.side_effect = OSError

        env = environment.Environment(is_global=True)
        env_dir = '/etc/senlin/environments'
        env.read_global_environment()

        mock_dir.assert_called_once_with(env_dir + '/*')
Esempio n. 6
0
    def test_register_and_get_driver_types(self):
        plugin = mock.Mock()
        env = environment.Environment()

        ex = self.assertRaises(exception.InvalidPlugin, env.get_driver, 'foo')
        self.assertEqual('Driver plugin foo is not found.', six.text_type(ex))

        env.register_driver('foo', plugin)
        self.assertEqual(plugin, env.get_driver('foo'))
Esempio n. 7
0
    def test_get_driver_types(self):
        env = environment.Environment()
        plugin1 = mock.Mock()
        env.register_driver('foo', plugin1)
        plugin2 = mock.Mock()
        env.register_driver('bar', plugin2)

        actual = env.get_driver_types()
        self.assertIn({'name': 'foo'}, actual)
        self.assertIn({'name': 'bar'}, actual)
Esempio n. 8
0
    def test_register_and_get_policy(self):
        plugin = mock.Mock()
        env = environment.Environment()

        ex = self.assertRaises(exception.ResourceNotFound, env.get_policy,
                               'foo')
        self.assertEqual("The policy_type 'foo' could not be found.", str(ex))

        env.register_policy('foo', plugin)
        self.assertEqual(plugin, env.get_policy('foo'))
Esempio n. 9
0
    def test_create_global(self):
        e = environment.Environment(is_global=True)

        self.assertEqual({}, e.params)
        self.assertEqual('profiles', e.profile_registry.registry_name)
        self.assertEqual('policies', e.policy_registry.registry_name)
        self.assertEqual('drivers', e.driver_registry.registry_name)
        self.assertTrue(e.profile_registry.is_global)
        self.assertTrue(e.policy_registry.is_global)
        self.assertTrue(e.driver_registry.is_global)
Esempio n. 10
0
    def test_register_and_get_policy(self):
        plugin = mock.Mock()
        env = environment.Environment()

        ex = self.assertRaises(exception.PolicyTypeNotFound, env.get_policy,
                               'foo')
        self.assertEqual('Policy type (foo) is not found.', six.text_type(ex))

        env.register_policy('foo', plugin)
        self.assertEqual(plugin, env.get_policy('foo'))
Esempio n. 11
0
    def test_register_and_get_endpoints(self):
        plugin = mock.Mock()
        env = environment.Environment()

        ex = self.assertRaises(exception.InvalidPlugin, env.get_endpoint,
                               'foo')
        self.assertEqual('Endpoint plugin foo is not found.', str(ex))

        env.register_endpoint('foo', plugin)
        self.assertEqual(plugin, env.get_endpoint('foo'))
Esempio n. 12
0
    def test_register_and_get_trigger_types(self):
        plugin = mock.Mock()
        env = environment.Environment()

        ex = self.assertRaises(exception.TriggerTypeNotFound,
                               env.get_trigger, 'foo')
        self.assertEqual('Trigger type (foo) is not found.',
                         six.text_type(ex))

        env.register_trigger('foo', plugin)
        self.assertEqual(plugin, env.get_trigger('foo'))
Esempio n. 13
0
    def test_register_and_get_profile(self):
        plugin = mock.Mock()
        env = environment.Environment()

        ex = self.assertRaises(exception.ResourceNotFound, env.get_profile,
                               'foo')
        self.assertEqual('The profile_type (foo) could not be found.',
                         six.text_type(ex))

        env.register_profile('foo', plugin)
        self.assertEqual(plugin, env.get_profile('foo'))
Esempio n. 14
0
    def test_read_global_environment(self):
        mock_dir = self.patchobject(glob, 'glob')
        mock_dir.return_value = ['/etc/senlin/environments/e.yaml']
        env_dir = '/etc/senlin/environments'
        env_contents = 'parameters:\n  p1: v1'
        env = environment.Environment(is_global=True)
        with mock.patch('senlin.engine.environment.open',
                        mock.mock_open(read_data=env_contents),
                        create=True) as mock_open:
            env.read_global_environment()

        mock_dir.assert_called_once_with(env_dir + '/*')
        mock_open.assert_called_once_with('%s/e.yaml' % env_dir)
Esempio n. 15
0
    def test_get_driver_types(self):
        env = environment.Environment()
        plugin1 = mock.Mock(VERSIONS={})
        env.register_driver('foo', plugin1)
        plugin2 = mock.Mock(VERSIONS={})
        env.register_driver('bar', plugin2)

        actual = env.get_driver_types()
        self.assertIn({
            'name': 'foo',
            'version': '',
            'support_status': {}
        }, actual)
        self.assertIn({
            'name': 'bar',
            'version': '',
            'support_status': {}
        }, actual)
Esempio n. 16
0
    def test_check_plugin_name(self):
        env = environment.Environment()

        for pt in ['Profile', 'Policy', 'Driver', 'Endpoint']:
            res = env._check_plugin_name(pt, 'abc')
            self.assertIsNone(res)

            ex = self.assertRaises(exception.InvalidPlugin,
                                   env._check_plugin_name, pt, '')
            self.assertEqual('%s type name not specified' % pt, str(ex))

            ex = self.assertRaises(exception.InvalidPlugin,
                                   env._check_plugin_name, pt, None)
            self.assertEqual('%s type name not specified' % pt, str(ex))

            for v in [123, {}, ['a'], ('b', 'c'), True]:
                ex = self.assertRaises(exception.InvalidPlugin,
                                       env._check_plugin_name, pt, v)
            self.assertEqual('%s type name is not a string' % pt, str(ex))
Esempio n. 17
0
    def test_parse(self):
        env = environment.Environment()
        result = env.parse(fake_env_str)

        self.assertEqual('va', result['parameters']['pa'])
        self.assertEqual('vb', result['parameters']['pb'])
        self.assertEqual('plugin_1', result['custom_profiles']['prof_1'])
        self.assertEqual('plugin_2', result['custom_policies']['policy_2'])

        # unknown sections
        env_str = "variables:\n  p1: v1"
        err = self.assertRaises(ValueError, env.parse, env_str)
        self.assertEqual('environment has unknown section "variables"',
                         six.text_type(err))

        # omitted sections
        env_str = "parameters:\n  p1: v1"
        result = env.parse(env_str)
        self.assertEqual('v1', result['parameters']['p1'])
        self.assertEqual({}, result['custom_profiles'])
        self.assertEqual({}, result['custom_policies'])
Esempio n. 18
0
    def test_get_policy_types(self):
        env = environment.Environment()
        plugin1 = mock.Mock(VERSIONS={'k': 'v'})
        env.register_policy('foo-0.1', plugin1)
        plugin2 = mock.Mock(VERSIONS={'k': 'v1'})
        env.register_policy('bar-0.2', plugin2)

        actual = env.get_policy_types()
        self.assertIn(
            {
                'name': 'foo',
                'version': '0.1',
                'support_status': {
                    'k': 'v'
                }
            }, actual)
        self.assertIn(
            {
                'name': 'bar',
                'version': '0.2',
                'support_status': {
                    'k': 'v1'
                }
            }, actual)
Esempio n. 19
0
 def test_parse_empty(self):
     env = environment.Environment()
     result = env.parse(None)
     self.assertEqual({}, result)