Esempio n. 1
0
 def setUp(self):
     super(ProfileTypeTest, self).setUp()
     self.ctx = utils.dummy_context(project='profile_type_test_project')
     self.eng = service.EngineService('host-a', 'topic-a')
     self.eng.init_tgm()
     environment.global_env().register_profile('TestProfile',
                                               fakes.TestProfile)
Esempio n. 2
0
 def setUp(self):
     super(TriggerTest, self).setUp()
     self.ctx = utils.dummy_context(project='trigger_test_project')
     self.eng = service.EngineService('host-a', 'topic-a')
     self.eng.init_tgm()
     environment.global_env().register_trigger('TestTrigger',
                                               fakes.TestTrigger)
Esempio n. 3
0
 def setUp(self):
     super(TriggerTest, self).setUp()
     self.ctx = utils.dummy_context(project='trigger_test_project')
     self.eng = service.EngineService('host-a', 'topic-a')
     self.eng.init_tgm()
     environment.global_env().register_trigger('TestTrigger',
                                               fakes.TestTrigger)
Esempio n. 4
0
 def setUp(self):
     super(PolicyTypeTest, self).setUp()
     self.ctx = utils.dummy_context(project='policy_type_test_project')
     self.eng = service.EngineService('host-a', 'topic-a')
     self.eng.init_tgm()
     environment.global_env().register_policy('TestPolicy',
                                              fakes.TestPolicy)
Esempio n. 5
0
 def setUp(self):
     super(PolicyTypeTest, self).setUp()
     self.ctx = utils.dummy_context(tenant_id='policy_type_test_tenant')
     self.eng = service.EngineService('host-a', 'topic-a')
     self.eng.init_tgm()
     environment.global_env().register_policy('TestPolicy',
                                              fakes.TestPolicy)
Esempio n. 6
0
 def setUp(self):
     super(TestPolicyBase, self).setUp()
     self.ctx = utils.dummy_context()
     environment.global_env().register_policy('senlin.policy.dummy-1.0',
                                              DummyPolicy)
     environment.global_env().register_policy('senlin.policy.dummy-1.1',
                                              DummyPolicy)
     self.spec = parser.simple_parse(sample_policy)
Esempio n. 7
0
 def setUp(self):
     super(PolicyTest, self).setUp()
     self.ctx = utils.dummy_context(project='policy_test_project')
     self.eng = service.EngineService('host-a', 'topic-a')
     self.eng.init_tgm()
     environment.global_env().register_policy('TestPolicy',
                                              fakes.TestPolicy)
     self.spec = {
         'type': 'TestPolicy',
         'version': '1.0',
         'properties': {
             'KEY1': 'value1',
             'KEY2': 2,
         }
     }
Esempio n. 8
0
    def _setup_fakes(self):
        """Set up fake policy for the purpose of testing.

        This method is provided in a standalone function because not all
        test cases need such a set up.
        """
        environment.global_env().register_policy('TestPolicy-1.0',
                                                 fakes.TestPolicy)
        self.spec = {
            'type': 'TestPolicy',
            'version': '1.0',
            'properties': {
                'KEY2': 6
            }
        }
Esempio n. 9
0
    def _setup_fakes(self):
        """Set up fake policy for the purpose of testing.

        This method is provided in a standalone function because not all
        test cases need such a set up.
        """
        environment.global_env().register_policy('TestPolicy-1.0',
                                                 fakes.TestPolicy)
        self.spec = {
            'type': 'TestPolicy',
            'version': '1.0',
            'properties': {
                'KEY2': 6
            }
        }
Esempio n. 10
0
    def test_node_create_profile_type_not_match(self, notify):
        env = environment.global_env()
        env.register_profile('SecondProfile', fakes.TestProfile)
        new_spec = {
            'type': 'SecondProfile',
            'version': '1.0',
            'properties': {
                'INT': 20,
                'STR': 'string'
            }
        }
        cluster_profile = self.eng.profile_create(self.ctx, 'cp', new_spec)

        cluster = self.eng.cluster_create(self.ctx, 'c-1', 0,
                                          cluster_profile['id'])

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_create,
                               self.ctx,
                               'n-1',
                               self.profile['id'],
                               cluster_id=cluster['id'])

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual(
            "Node and cluster have different profile type, "
            "operation aborted.", six.text_type(ex.exc_info[1]))
Esempio n. 11
0
    def test_node_join_profile_type_not_match(self, notify):
        # prepare a cluster with different profile type
        env = environment.global_env()
        env.register_profile('OtherProfileType', fakes.TestProfile)
        other_spec = {
            'type': 'OtherProfileType',
            'version': '1.0',
            'properties': {
                'INT': 20,
                'STR': 'okay',
            }
        }
        other_profile = self.eng.profile_create(self.ctx, 'new-profile',
                                                other_spec)

        c = self.eng.cluster_create(self.ctx, 'c-1', 0, other_profile['id'])
        cluster_id = c['id']

        node = self.eng.node_create(self.ctx, 'node1', self.profile['id'])
        node_id = node['id']

        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_join,
                               self.ctx, node_id, cluster_id)

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual(
            'Node and cluster have different profile type, '
            'operation aborted.', six.text_type(ex.exc_info[1]))
Esempio n. 12
0
    def test_node_join_profile_type_not_match(self, notify):
        # prepare a cluster with different profile type
        env = environment.global_env()
        env.register_profile('OtherProfileType', fakes.TestProfile)
        other_spec = {
            'type': 'OtherProfileType',
            'version': '1.0',
            'properties': {
                'INT': 20,
                'STR': 'okay',
            }
        }
        other_profile = self.eng.profile_create(self.ctx, 'new-profile',
                                                other_spec)

        c = self.eng.cluster_create(self.ctx, 'c-1', 0, other_profile['id'])
        cluster_id = c['id']

        node = self.eng.node_create(self.ctx, 'node1', self.profile['id'])
        node_id = node['id']

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_join,
                               self.ctx, node_id, cluster_id)

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual('Node and cluster have different profile type, '
                         'operation aborted.',
                         six.text_type(ex.exc_info[1]))
Esempio n. 13
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. 14
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. 15
0
    def test_cluster_add_nodes_node_profile_type_not_match(self, notify):
        c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
        # Register a different profile
        env = environment.global_env()
        env.register_profile('DiffProfileType', fakes.TestProfile)
        new_spec = {
            'type': 'DiffProfileType',
            'version': '1.0',
            'properties': {
                'INT': 10,
                'STR': 'string'
            },
        }
        new_profile = self.eng.profile_create(self.ctx,
                                              'p-test',
                                              new_spec,
                                              permission='1111')
        nodes = self._prepare_nodes(self.ctx,
                                    count=1,
                                    profile_id=new_profile['id'])

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_add_nodes, self.ctx, c['id'],
                               nodes)

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        msg = _("Profile type of nodes %s does not match with "
                "cluster") % nodes
        self.assertEqual(msg, six.text_type(ex.exc_info[1]))
Esempio n. 16
0
    def setUp(self):
        super(ClusterTest, self).setUp()
        self.ctx = utils.dummy_context(project='cluster_test_project')
        self.eng = service.EngineService('host-a', 'topic-a')
        self.eng.init_tgm()

        self.eng.dispatcher = mock.Mock()

        env = environment.global_env()
        env.register_profile('TestProfile', fakes.TestProfile)
        env.register_policy('TestPolicy', fakes.TestPolicy)

        spec = {
            'type': 'TestProfile',
            'version': '1.0',
            'properties': {'INT': 10, 'STR': 'string'},
        }
        self.profile = self.eng.profile_create(self.ctx, 'p-test', spec,
                                               permission='1111')
        spec = {
            'type': 'TestPolicy',
            'version': '1.0',
            'properties': {'KEY2': 3}
        }
        self.policy = self.eng.policy_create(self.ctx, 'policy_1', spec,
                                             cooldown=60, level=50)
Esempio n. 17
0
 def setUp(self):
     super(TestProfileBase, self).setUp()
     self.ctx = utils.dummy_context(project='profile_test_project')
     g_env = environment.global_env()
     g_env.register_profile('os.dummy-1.0', DummyProfile)
     g_env.register_profile('os.dummy-1.1', DummyProfile)
     self.spec = parser.simple_parse(sample_profile)
Esempio n. 18
0
    def test_cluster_update_update_to_diff_profile_type(self, notify):
        # Register a different profile
        env = environment.global_env()
        env.register_profile('DiffProfileType', fakes.TestProfile)
        new_spec = {
            'type': 'DiffProfileType',
            'version': '1.0',
            'properties': {
                'INT': 10,
                'STR': 'string'
            },
        }
        new_profile = self.eng.profile_create(self.ctx,
                                              'p-test',
                                              new_spec,
                                              permission='1111')

        c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_update,
                               self.ctx,
                               c['id'],
                               profile_id=new_profile['id'])

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
Esempio n. 19
0
    def _setup_fakes(self):
        """Set up fake proflie for the purpose of testing.

        This method is provided in a standalone function because not all
        test cases need such a set up.
        """
        environment.global_env().register_profile('TestProfile-1.0',
                                                  fakes.TestProfile)
        self.spec = {
            'type': 'TestProfile',
            'version': '1.0',
            'properties': {
                'INT': 1,
                'STR': 'str',
                'LIST': ['v1', 'v2'],
                'MAP': {'KEY1': 1, 'KEY2': 'v2'},
            }
        }
Esempio n. 20
0
    def setUp(self):
        super(ProfileTest, self).setUp()
        self.ctx = utils.dummy_context(project='profile_test_project')
        self.eng = service.EngineService('host-a', 'topic-a')
        self.eng.init_tgm()
        environment.global_env().register_profile('TestProfile',
                                                  fakes.TestProfile)

        self.spec = {
            'type': 'TestProfile',
            'version': '1.0',
            'properties': {
                'INT': 1,
                'STR': 'str',
                'LIST': ['v1', 'v2'],
                'MAP': {'KEY1': 1, 'KEY2': 'v2'},
            }
        }
Esempio n. 21
0
    def _setup_fakes(self):
        """Set up fake proflie for the purpose of testing.

        This method is provided in a standalone function because not all
        test cases need such a set up.
        """
        environment.global_env().register_profile('TestProfile-1.0',
                                                  fakes.TestProfile)
        self.spec = {
            'type': 'TestProfile',
            'version': '1.0',
            'properties': {
                'INT': 1,
                'STR': 'str',
                'LIST': ['v1', 'v2'],
                'MAP': {'KEY1': 1, 'KEY2': 'v2'},
            }
        }
Esempio n. 22
0
    def __new__(cls, ctx, type_name, name, **kwargs):
        '''Create a new profile of the appropriate class.'''

        if cls != Profile:
            ProfileClass = cls
        else:
            ProfileClass = environment.global_env().get_profile(type_name)

        return super(Profile, cls).__new__(ProfileClass)
Esempio n. 23
0
    def __new__(cls, type_name, name, **kwargs):
        '''Create a new policy of the appropriate class.'''

        if cls != Policy:
            PolicyClass = cls
        else:
            PolicyClass = environment.global_env().get_policy(type_name)

        return super(Policy, cls).__new__(PolicyClass)
Esempio n. 24
0
    def test_global_initialize(self, mock_mapping):
        mock_mapping.return_value = [['aaa', mock.Mock()]]

        environment._environment = None
        environment.initialize()

        expected = [mock.call('senlin.profiles'),
                    mock.call('senlin.policies'),
                    mock.call('senlin.triggers'),
                    mock.call('senlin.drivers')]

        self.assertIsNotNone(environment._environment)
        self.assertEqual(expected, mock_mapping.call_args_list)
        self.assertIsNotNone(environment.global_env().get_profile('aaa'))
        self.assertIsNotNone(environment.global_env().get_policy('aaa'))
        self.assertIsNotNone(environment.global_env().get_trigger('aaa'))
        self.assertIsNotNone(environment.global_env().get_driver('aaa'))

        environment._environment = None
Esempio n. 25
0
    def test_init_using_specified_cloud_backend(self):
        plugin2 = mock.Mock()
        plugin2.compute = 'Compute2'
        plugin2.orchestration = 'Orchestration2'
        env = environment.global_env()
        env.register_driver('cloud_backend_2', plugin2)

        # Using specified cloud backend
        sd = driver_base.SenlinDriver('cloud_backend_2')
        self.assertEqual('Compute2', sd.compute)
        self.assertEqual('Orchestration2', sd.orchestration)
Esempio n. 26
0
    def test_init_using_specified_cloud_backend(self):
        plugin2 = mock.Mock()
        plugin2.compute = 'Compute2'
        plugin2.orchestration = 'Orchestration2'
        env = environment.global_env()
        env.register_driver('openstack_test', plugin2)

        sd = driver_base.SenlinDriver('openstack_test')

        self.assertEqual('Compute2', sd.compute)
        self.assertEqual('Orchestration2', sd.orchestration)
Esempio n. 27
0
    def test_global_initialize(self, mock_mapping):
        mock_mapping.return_value = [["aaa", mock.Mock()]]

        environment._environment = None
        environment.initialize()

        expected = [
            mock.call("senlin.profiles"),
            mock.call("senlin.policies"),
            mock.call("senlin.triggers"),
            mock.call("senlin.drivers"),
        ]

        self.assertIsNotNone(environment._environment)
        self.assertEqual(expected, mock_mapping.call_args_list)
        self.assertIsNotNone(environment.global_env().get_profile("aaa"))
        self.assertIsNotNone(environment.global_env().get_policy("aaa"))
        self.assertIsNotNone(environment.global_env().get_trigger("aaa"))
        self.assertIsNotNone(environment.global_env().get_driver("aaa"))

        environment._environment = None
Esempio n. 28
0
    def test_init_using_default_cloud_backend(self):
        plugin1 = mock.Mock()
        plugin1.compute = 'Compute1'
        plugin1.orchestration = 'Orchestration1'
        env = environment.global_env()
        env.register_driver('cloud_backend_1', plugin1)

        # Using default cloud backend defined in configure file
        cfg.CONF.set_override('cloud_backend', 'cloud_backend_1')
        sd = driver_base.SenlinDriver()
        self.assertEqual('Compute1', sd.compute)
        self.assertEqual('Orchestration1', sd.orchestration)
Esempio n. 29
0
    def test_init_using_default_cloud_backend(self):
        plugin1 = mock.Mock()
        plugin1.compute = 'Compute1'
        plugin1.orchestration = 'Orchestration1'
        env = environment.global_env()
        env.register_driver('openstack_test', plugin1)
        cfg.CONF.set_override('cloud_backend', 'openstack_test')

        sd = driver_base.SenlinDriver()

        self.assertEqual('Compute1', sd.compute)
        self.assertEqual('Orchestration1', sd.orchestration)
Esempio n. 30
0
    def setUp(self):
        super(NodeTest, self).setUp()
        self.ctx = utils.dummy_context(project="node_test_project")
        self.eng = service.EngineService("host-a", "topic-a")
        self.eng.init_tgm()

        self.eng.dispatcher = mock.Mock()

        env = environment.global_env()
        env.register_profile("TestProfile", fakes.TestProfile)

        self.spec = {"type": "TestProfile", "version": "1.0", "properties": {"INT": 10, "STR": "string"}}
        self.profile = self.eng.profile_create(self.ctx, "p-test", self.spec, permission="1111")
Esempio n. 31
0
    def test_cluster_update_update_to_diff_profile_type(self, notify):
        # Register a different profile
        env = environment.global_env()
        env.register_profile('DiffProfileType', fakes.TestProfile)
        new_profile = self.eng.profile_create(
            self.ctx, 'p-test', 'DiffProfileType',
            spec={'INT': 10, 'STR': 'string'}, perm='1111')

        c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_update,
                               self.ctx, c['id'], profile_id=new_profile['id'])

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
Esempio n. 32
0
    def test_init_using_default_cloud_backend(self):
        plugin1 = mock.Mock()
        plugin1.compute = 'Compute1'
        plugin1.orchestration = 'Orchestration1'
        env = environment.global_env()
        env.register_driver('cloud_backend_1', plugin1)

        # Using default cloud backend defined in configure file
        cfg.CONF.set_override('cloud_backend',
                              'cloud_backend_1',
                              enforce_type=True)
        sd = driver_base.SenlinDriver()
        self.assertEqual('Compute1', sd.compute)
        self.assertEqual('Orchestration1', sd.orchestration)
Esempio n. 33
0
    def __init__(self, backend_name=None):

        if backend_name is None:
            backend_name = cfg.CONF.cloud_backend

        backend = environment.global_env().get_driver(backend_name)

        self.compute = backend.compute
        self.loadbalancing = backend.loadbalancing
        self.network = backend.network
        self.orchestration = backend.orchestration
        self.telemetry = backend.telemetry
        self.identity = backend.identity
        self.message = backend.message
Esempio n. 34
0
    def _prepare_policy(self, name, type_name=None, cooldown=None, level=None):
        if type_name is not None:
            env = environment.global_env()
            env.register_policy(type_name, fakes.TestPolicy)
        else:
            type_name = 'TestPolicy'
        spec = {'type': type_name, 'version': '1.0', 'properties': {'KEY2': 5}}
        policy = self.eng.policy_create(self.ctx,
                                        name,
                                        spec,
                                        cooldown=cooldown or 60,
                                        level=level or 50)

        return policy
Esempio n. 35
0
    def __init__(self, backend_name=None):

        if backend_name is None:
            backend_name = cfg.CONF.cloud_backend

        backend = environment.global_env().get_driver(backend_name)

        # TODO(Yanyan Hu): Use openstack compute driver(nova_v2)
        # as the start point of using senlin generic driver.
        self.compute = backend.compute
        self.loadbalancing = backend.loadbalancing
        self.network = backend.network
        self.orchestration = backend.orchestration
        self.telemetry = backend.telemetry
        self.identity = backend.identity
Esempio n. 36
0
    def __init__(self, backend_name=None):

        if backend_name is None:
            backend_name = cfg.CONF.cloud_backend

        backend = environment.global_env().get_driver(backend_name)

        # TODO(Yanyan Hu): Use openstack compute driver(nova_v2)
        # as the start point of using senlin generic driver.
        self.compute = backend.compute
        self.loadbalancing = backend.loadbalancing
        self.network = backend.network
        self.orchestration = backend.orchestration
        self.telemetry = backend.telemetry
        self.identity = backend.identity
Esempio n. 37
0
    def __new__(cls, name, spec, **kwargs):
        """Create a new profile of the appropriate class.

        :param name: The name for the profile.
        :param spec: A dictionary containing the spec for the profile.
        :param kwargs: Keyword arguments for policy creation.
        :returns: An instance of a specific sub-class of Policy.
        """
        type_name, version = schema.get_spec_version(spec)

        if cls != Profile:
            ProfileClass = cls
        else:
            ProfileClass = environment.global_env().get_profile(type_name)

        return super(Profile, cls).__new__(ProfileClass)
Esempio n. 38
0
    def __new__(cls, name, spec, **kwargs):
        """Create a trigger instance based on its type and version.

        :param name: The name for the trigger.
        :param spec: A dictionary containing the spec for the trigger.
        :param kwargs: Keyword arguments for trigger creation.
        :returns: An instance of a specific sub-class of BaseTrigger.
        """
        type_name, version = schema.get_spec_version(spec)

        if cls != Trigger:
            TriggerClass = cls
        else:
            TriggerClass = environment.global_env().get_trigger(type_name)

        return super(Trigger, cls).__new__(TriggerClass)
Esempio n. 39
0
    def _prepare_policy(self, name, type_name=None, cooldown=None, level=None):
        if type_name is not None:
            env = environment.global_env()
            env.register_policy(type_name, fakes.TestPolicy)
        else:
            type_name = 'TestPolicy'
        spec = {
            'type': type_name,
            'version': '1.0',
            'properties': {'KEY2': 5}
        }
        policy = self.eng.policy_create(self.ctx, name, spec,
                                        cooldown=cooldown or 60,
                                        level=level or 50)

        return policy
Esempio n. 40
0
    def test_node_create_profile_type_not_match(self, notify):
        env = environment.global_env()
        env.register_profile("SecondProfile", fakes.TestProfile)
        new_spec = {"type": "SecondProfile", "version": "1.0", "properties": {"INT": 20, "STR": "string"}}
        cluster_profile = self.eng.profile_create(self.ctx, "cp", new_spec)

        cluster = self.eng.cluster_create(self.ctx, "c-1", 0, cluster_profile["id"])

        ex = self.assertRaises(
            rpc.ExpectedException, self.eng.node_create, self.ctx, "n-1", self.profile["id"], cluster_id=cluster["id"]
        )

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual(
            "Node and cluster have different profile type, " "operation aborted.", six.text_type(ex.exc_info[1])
        )
Esempio n. 41
0
    def test_node_update_with_diff_profile_type(self, notify):
        env = environment.global_env()
        env.register_profile("NewProfileType", fakes.TestProfile)
        new_spec = {"type": "NewProfileType", "version": "1.0", "properties": {"INT": 20}}
        new_profile = self.eng.profile_create(self.ctx, "p-new", new_spec)

        node = self.eng.node_create(self.ctx, "node-1", self.profile["id"])

        ex = self.assertRaises(
            rpc.ExpectedException, self.eng.node_update, self.ctx, node["id"], profile_id=new_profile["id"]
        )

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual(
            "Cannot update a node to a different profile type, " "operation aborted.", six.text_type(ex.exc_info[1])
        )
Esempio n. 42
0
    def __init__(self, backend_name=None):

        if backend_name is None:
            backend_name = cfg.CONF.cloud_backend

        backend = environment.global_env().get_driver(backend_name)

        self.compute = backend.compute
        self.loadbalancing = backend.loadbalancing
        self.network = backend.network
        self.octavia = backend.octavia
        self.orchestration = backend.orchestration
        self.identity = backend.identity
        self.message = backend.message
        self.workflow = backend.workflow
        self.block_storage = backend.block_storage
Esempio n. 43
0
    def __new__(cls, name, spec, **kwargs):
        """Create a trigger instance based on its type and version.

        :param name: The name for the trigger.
        :param spec: A dictionary containing the spec for the trigger.
        :param kwargs: Keyword arguments for trigger creation.
        :returns: An instance of a specific sub-class of BaseTrigger.
        """
        type_name, version = schema.get_spec_version(spec)

        if cls != Trigger:
            TriggerClass = cls
        else:
            TriggerClass = environment.global_env().get_trigger(type_name)

        return super(Trigger, cls).__new__(TriggerClass)
Esempio n. 44
0
    def __new__(cls, name, spec, **kwargs):
        """Create a new profile of the appropriate class.

        :param name: The name for the profile.
        :param spec: A dictionary containing the spec for the profile.
        :param kwargs: Keyword arguments for policy creation.
        :returns: An instance of a specific sub-class of Policy.
        """
        type_name, version = schema.get_spec_version(spec)

        if cls != Profile:
            ProfileClass = cls
        else:
            ProfileClass = environment.global_env().get_profile(type_name)

        return super(Profile, cls).__new__(ProfileClass)
Esempio n. 45
0
    def test_node_join_profile_type_not_match(self, notify):
        # prepare a cluster with different profile type
        env = environment.global_env()
        env.register_profile("OtherProfileType", fakes.TestProfile)
        other_spec = {"type": "OtherProfileType", "version": "1.0", "properties": {"INT": 20, "STR": "okay"}}
        other_profile = self.eng.profile_create(self.ctx, "new-profile", other_spec)

        c = self.eng.cluster_create(self.ctx, "c-1", 0, other_profile["id"])
        cluster_id = c["id"]

        node = self.eng.node_create(self.ctx, "node1", self.profile["id"])
        node_id = node["id"]

        ex = self.assertRaises(rpc.ExpectedException, self.eng.node_join, self.ctx, node_id, cluster_id)

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual(
            "Node and cluster have different profile type, " "operation aborted.", six.text_type(ex.exc_info[1])
        )
Esempio n. 46
0
    def setUp(self):
        super(ClusterTest, self).setUp()
        self.ctx = utils.dummy_context(tenant_id='cluster_test_tenant')
        self.eng = service.EngineService('host-a', 'topic-a')
        self.eng.init_tgm()

        self.eng.dispatcher = mock.Mock()

        env = environment.global_env()
        env.register_profile('TestProfile', fakes.TestProfile)
        env.register_policy('TestPolicy', fakes.TestPolicy)

        self.profile = self.eng.profile_create(
            self.ctx, 'p-test', 'TestProfile',
            spec={'INT': 10, 'STR': 'string'}, perm='1111')

        self.policy = self.eng.policy_create(
            self.ctx, 'policy_1', 'TestPolicy',
            spec={'KEY1': 'string'}, cooldown=60, level=50)
Esempio n. 47
0
    def setUp(self):
        super(WebhookTest, self).setUp()
        self.ctx = utils.dummy_context(project='webhook_test_project')
        self.eng = service.EngineService('host-a', 'topic-a')
        self.eng.init_tgm()
        self.eng.dispatcher = mock.Mock()

        env = environment.global_env()
        env.register_profile('TestProfile', fakes.TestProfile)

        spec = {
            'type': 'TestProfile',
            'version': '1.0',
            'properties': {
                'INT': 10,
                'STR': 'string'
            }
        }
        self.profile = self.eng.profile_create(self.ctx, 'p-test', spec,
                                               permission='1111')
Esempio n. 48
0
    def setUp(self):
        super(ClusterPolicyTest, self).setUp()
        self.ctx = utils.dummy_context(project='cluster_policy_test_project')
        self.eng = service.EngineService('host-a', 'topic-a')
        self.eng.init_tgm()

        self.eng.dispatcher = mock.Mock()
        self.patchobject(dispatcher, 'notify')

        env = environment.global_env()
        env.register_profile('TestProfile', fakes.TestProfile)
        env.register_policy('TestPolicy', fakes.TestPolicy)

        profile_spec = {
            'type': 'TestProfile',
            'version': '1.0',
            'properties': {
                'INT': 10,
                'STR': 'string'
            },
        }
        self.profile = self.eng.profile_create(self.ctx,
                                               'p-test',
                                               profile_spec,
                                               permission='1111')

        policy_spec = {
            'type': 'TestPolicy',
            'version': '1.0',
            'properties': {
                'KEY2': 5
            },
        }
        self.policy = self.eng.policy_create(self.ctx,
                                             'policy_1',
                                             policy_spec,
                                             cooldown=6,
                                             level=5)

        self.cluster = self.eng.cluster_create(self.ctx, 'c-1', 0,
                                               self.profile['id'])
Esempio n. 49
0
    def test_node_update_with_diff_profile_type(self, notify):
        env = environment.global_env()
        env.register_profile('NewProfileType', fakes.TestProfile)
        new_spec = {
            'type': 'NewProfileType',
            'version': '1.0',
            'properties': {'INT': 20},
        }
        new_profile = self.eng.profile_create(self.ctx, 'p-new', new_spec)

        node = self.eng.node_create(self.ctx, 'node-1', self.profile['id'])

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_update,
                               self.ctx, node['id'],
                               profile_id=new_profile['id'])

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual('Cannot update a node to a different profile type, '
                         'operation aborted.',
                         six.text_type(ex.exc_info[1]))
Esempio n. 50
0
    def test_node_create_profile_type_not_match(self, notify):
        env = environment.global_env()
        env.register_profile('SecondProfile', fakes.TestProfile)
        new_spec = {
            'type': 'SecondProfile',
            'version': '1.0',
            'properties': {'INT': 20, 'STR': 'string'}
        }
        cluster_profile = self.eng.profile_create(self.ctx, 'cp', new_spec)

        cluster = self.eng.cluster_create(self.ctx, 'c-1', 0,
                                          cluster_profile['id'])

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_create,
                               self.ctx, 'n-1', self.profile['id'],
                               cluster_id=cluster['id'])

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual("Node and cluster have different profile type, "
                         "operation aborted.",
                         six.text_type(ex.exc_info[1]))
Esempio n. 51
0
    def setUp(self):
        super(WebhookTest, self).setUp()
        self.ctx = utils.dummy_context(project='webhook_test_project')
        self.eng = service.EngineService('host-a', 'topic-a')
        self.eng.init_tgm()
        self.eng.dispatcher = mock.Mock()

        env = environment.global_env()
        env.register_profile('TestProfile', fakes.TestProfile)

        spec = {
            'type': 'TestProfile',
            'version': '1.0',
            'properties': {
                'INT': 10,
                'STR': 'string'
            }
        }
        self.profile = self.eng.profile_create(self.ctx,
                                               'p-test',
                                               spec,
                                               permission='1111')
Esempio n. 52
0
    def test_cluster_add_nodes_node_profile_type_not_match(self, notify):
        c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
        # Register a different profile
        env = environment.global_env()
        env.register_profile('DiffProfileType', fakes.TestProfile)
        new_spec = {
            'type': 'DiffProfileType',
            'version': '1.0',
            'properties': {'INT': 10, 'STR': 'string'},
        }
        new_profile = self.eng.profile_create(
            self.ctx, 'p-test', new_spec, permission='1111')
        nodes = self._prepare_nodes(self.ctx, count=1,
                                    profile_id=new_profile['id'])

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_add_nodes,
                               self.ctx, c['id'], nodes)

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        msg = _("Profile type of nodes %s does not match with "
                "cluster") % nodes
        self.assertEqual(msg, six.text_type(ex.exc_info[1]))
Esempio n. 53
0
    def test_node_update_with_diff_profile_type(self, notify):
        env = environment.global_env()
        env.register_profile('NewProfileType', fakes.TestProfile)
        new_spec = {
            'type': 'NewProfileType',
            'version': '1.0',
            'properties': {
                'INT': 20
            },
        }
        new_profile = self.eng.profile_create(self.ctx, 'p-new', new_spec)

        node = self.eng.node_create(self.ctx, 'node-1', self.profile['id'])

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.node_update,
                               self.ctx,
                               node['id'],
                               profile_id=new_profile['id'])

        self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
        self.assertEqual(
            'Cannot update a node to a different profile type, '
            'operation aborted.', six.text_type(ex.exc_info[1]))
Esempio n. 54
0
    def setUp(self):

        super(TestTriggerBase, self).setUp()
        self.ctx = utils.dummy_context()
        environment.global_env().register_trigger('FakeTriggerType',
                                                  FakeTriggerImpl)
Esempio n. 55
0
    def setUp(self):

        super(TestTriggerBase, self).setUp()
        self.ctx = utils.dummy_context()
        environment.global_env().register_trigger('FakeTriggerType',
                                                  FakeTriggerImpl)
Esempio n. 56
0
 def setUp(self):
     super(TestPolicyBase, self).setUp()
     self.ctx = utils.dummy_context()
     environment.global_env().register_policy('senlin.policy.dummy',
                                              DummyPolicy)
     self.spec = parser.simple_parse(sample_policy)
Esempio n. 57
0
    def setUp(self):
        super(ActionPolicyCheckTest, self).setUp()

        self.ctx = utils.dummy_context()
        environment.global_env().register_policy('DummyPolicy',
                                                 fakes.TestPolicy)