예제 #1
0
    def test_env_multi_resources_disable(self):
        # prove we can disable resources in the global environment

        g_env_content = '''
        resource_registry:
            "AWS::*":
        '''
        # 1. fake an environment file
        envdir = self.useFixture(fixtures.TempDir())
        envfile = os.path.join(envdir.path, 'test.yaml')
        with open(envfile, 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir',
                              envdir.path,
                              enforce_type=True)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_global_environment(g_env)

        # 3. assert our resources are now gone.
        self.assertRaises(exception.EntityNotFound, g_env.get_resource_info,
                          'AWS::EC2::Instance')

        # 4. make sure we haven't removed something we shouldn't have
        self.assertEqual(server.Server,
                         g_env.get_resource_info('OS::Nova::Server').value)
예제 #2
0
    def test_env_ignore_files_starting_dot(self):
        # prove we can disable a resource in the global environment

        g_env_content = ''
        # 1. fake an environment file
        envdir = self.useFixture(fixtures.TempDir())
        with open(os.path.join(envdir.path, 'a.yaml'), 'w+') as ef:
            ef.write(g_env_content)
        with open(os.path.join(envdir.path, '.test.yaml'), 'w+') as ef:
            ef.write(g_env_content)
        with open(os.path.join(envdir.path, 'b.yaml'), 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir', envdir.path)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        with mock.patch('heat.engine.environment.open',
                        mock.mock_open(read_data=g_env_content),
                        create=True) as m_open:
            resources._load_global_environment(g_env)

        # 3. assert that the file were ignored
        expected = [
            mock.call('%s/a.yaml' % envdir.path),
            mock.call('%s/b.yaml' % envdir.path)
        ]
        call_list = m_open.call_args_list

        expected.sort()
        call_list.sort()

        self.assertEqual(expected, call_list)
예제 #3
0
    def test_env_resources_override_plugins(self):
        # assertion: any template resources in the global environment
        #            should override the default plugins.

        # 1. set our own global test env
        #    (with a template resource that shadows a plugin)
        g_env_content = '''
        resource_registry:
          "OS::Nova::Server": "file:///not_really_here.yaml"
        '''
        envdir = self.useFixture(fixtures.TempDir())
        #
        envfile = os.path.join(envdir.path, 'test.yaml')
        with open(envfile, 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir',
                              envdir.path,
                              enforce_type=True)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_global_environment(g_env)

        # 3. assert our resource is in place.
        self.assertEqual('file:///not_really_here.yaml',
                         g_env.get_resource_info('OS::Nova::Server').value)
예제 #4
0
    def test_constraints_registry_stevedore(self):
        env = environment.Environment({})
        resources._load_global_environment(env)

        self.assertEqual("FlavorConstraint",
                         env.get_constraint("nova.flavor").__name__)
        self.assertIs(None, env.get_constraint("no_constraint"))
예제 #5
0
    def test_constraints_registry_stevedore(self):
        env = environment.Environment({})
        resources._load_global_environment(env)

        self.assertEqual("FlavorConstraint",
                         env.get_constraint("nova.flavor").__name__)
        self.assertIs(None, env.get_constraint("no_constraint"))
예제 #6
0
    def test_env_ignore_files_starting_dot(self):
        # prove we can disable a resource in the global environment

        g_env_content = ''
        # 1. fake an environment file
        envdir = self.useFixture(fixtures.TempDir())
        with open(os.path.join(envdir.path, 'a.yaml'), 'w+') as ef:
            ef.write(g_env_content)
        with open(os.path.join(envdir.path, '.test.yaml'), 'w+') as ef:
            ef.write(g_env_content)
        with open(os.path.join(envdir.path, 'b.yaml'), 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir', envdir.path)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        with mock.patch('heat.engine.environment.open',
                        mock.mock_open(read_data=g_env_content),
                        create=True) as m_open:
            resources._load_global_environment(g_env)

        # 3. assert that the file were ignored
        expected = [mock.call('%s/a.yaml' % envdir.path),
                    mock.call('%s/b.yaml' % envdir.path)]
        call_list = m_open.call_args_list

        expected.sort()
        call_list.sort()

        self.assertEqual(expected, call_list)
예제 #7
0
    def test_env_multi_resources_disable(self):
        # prove we can disable resources in the global environment

        g_env_content = '''
        resource_registry:
            "AWS::*":
        '''
        # 1. fake an environment file
        envdir = self.useFixture(fixtures.TempDir())
        envfile = os.path.join(envdir.path, 'test.yaml')
        with open(envfile, 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir', envdir.path,
                              enforce_type=True)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_global_environment(g_env)

        # 3. assert our resources are now gone.
        self.assertRaises(exception.EntityNotFound,
                          g_env.get_resource_info, 'AWS::EC2::Instance')

        # 4. make sure we haven't removed something we shouldn't have
        self.assertEqual(server.Server,
                         g_env.get_resource_info('OS::Nova::Server').value)
예제 #8
0
    def test_env_resources_override_plugins(self):
        # assertion: any template resources in the global environment
        #            should override the default plugins.

        # 1. set our own global test env
        #    (with a template resource that shadows a plugin)
        g_env_content = '''
        resource_registry:
          "OS::Nova::Server": "file:///not_really_here.yaml"
        '''
        envdir = self.useFixture(fixtures.TempDir())
        #
        envfile = os.path.join(envdir.path, 'test.yaml')
        with open(envfile, 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir', envdir.path,
                              enforce_type=True)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_global_environment(g_env)

        # 3. assert our resource is in place.
        self.assertEqual('file:///not_really_here.yaml',
                         g_env.get_resource_info('OS::Nova::Server').value)
예제 #9
0
    def test_continue_on_parse_error(self):
        """assert we get all files processed even if there are
        processing exceptions.
        """
        list_dir = 'heat.engine.resources._list_environment_files'
        with mock.patch(list_dir) as m_ldir:
            m_ldir.return_value = [
                '/etc_etc/heat/enviroment.d/a.yaml',
                '/etc_etc/heat/enviroment.d/b.yaml'
            ]
            env_dir = '/etc_etc/heat/enviroment.d'
            env_content = '{@$%#$%'

            with mock.patch('heat.engine.resources.open',
                            mock.mock_open(read_data=env_content),
                            create=True) as m_open:
                resources._load_global_environment(resources.global_env(),
                                                   env_dir)

        m_ldir.assert_called_once_with(env_dir)
        expected = [
            mock.call('%s/a.yaml' % env_dir),
            mock.call('%s/b.yaml' % env_dir)
        ]
        self.assertEqual(expected, m_open.call_args_list)
예제 #10
0
    def test_empty_env_dir(self):
        list_dir = 'heat.engine.resources._list_environment_files'
        with mock.patch(list_dir) as m_ldir:
            m_ldir.return_value = []
            env_dir = '/etc_etc/heat/enviroment.d'
            resources._load_global_environment(env_dir)

        m_ldir.assert_called_once_with(env_dir)
예제 #11
0
    def test_empty_env_dir(self):
        list_dir = 'heat.engine.resources._list_environment_files'
        with mock.patch(list_dir) as m_ldir:
            m_ldir.return_value = []
            env_dir = '/etc_etc/heat/enviroment.d'
            resources._load_global_environment(resources.global_env(), env_dir)

        m_ldir.assert_called_once_with(env_dir)
예제 #12
0
    def test_happy_path(self):
        list_dir = "heat.engine.resources._list_environment_files"
        with mock.patch(list_dir) as m_ldir:
            m_ldir.return_value = ["/etc_etc/heat/environment.d/a.yaml"]
            env_dir = "/etc_etc/heat/environment.d"
            env_content = '{"resource_registry": {}}'

            with mock.patch("heat.engine.resources.open", mock.mock_open(read_data=env_content), create=True) as m_open:
                resources._load_global_environment(resources.global_env(), env_dir)

        m_ldir.assert_called_once_with(env_dir)
        m_open.assert_called_once_with("%s/a.yaml" % env_dir)
예제 #13
0
    def test_happy_path(self):
        list_dir = 'heat.engine.resources._list_environment_files'
        with mock.patch(list_dir) as m_ldir:
            m_ldir.return_value = ['a.yaml']
            env_dir = '/etc_etc/heat/enviroment.d'
            env_content = '{"resource_registry": {}}'

            with mock.patch('heat.engine.resources.open',
                            mock.mock_open(read_data=env_content),
                            create=True) as m_open:
                resources._load_global_environment(env_dir)

        m_ldir.assert_called_once_with(env_dir)
        m_open.assert_called_once_with('%s/a.yaml' % env_dir)
예제 #14
0
    def test_continue_on_parse_error(self):
        """assert we get all files processed even if there are
        processing exceptions.
        """
        list_dir = "heat.engine.resources._list_environment_files"
        with mock.patch(list_dir) as m_ldir:
            m_ldir.return_value = ["/etc_etc/heat/environment.d/a.yaml", "/etc_etc/heat/environment.d/b.yaml"]
            env_dir = "/etc_etc/heat/environment.d"
            env_content = "{@$%#$%"

            with mock.patch("heat.engine.resources.open", mock.mock_open(read_data=env_content), create=True) as m_open:
                resources._load_global_environment(resources.global_env(), env_dir)

        m_ldir.assert_called_once_with(env_dir)
        expected = [mock.call("%s/a.yaml" % env_dir), mock.call("%s/b.yaml" % env_dir)]
        self.assertEqual(expected, m_open.call_args_list)
예제 #15
0
    def test_continue_on_parse_error(self):
        """assert we get all files processed even if there are
        processing exceptions.
        """
        list_dir = 'heat.engine.resources._list_environment_files'
        with mock.patch(list_dir) as m_ldir:
            m_ldir.return_value = ['a.yaml', 'b.yaml']
            env_dir = '/etc_etc/heat/enviroment.d'
            env_content = '{@$%#$%'

            with mock.patch('heat.engine.resources.open',
                            mock.mock_open(read_data=env_content),
                            create=True) as m_open:
                resources._load_global_environment(env_dir)

        m_ldir.assert_called_once_with(env_dir)
        expected = [mock.call('%s/a.yaml' % env_dir),
                    mock.call('%s/b.yaml' % env_dir)]
        self.assertEqual(expected, m_open.call_args_list)
예제 #16
0
    def test_constraints_registry(self):
        constraint_content = """
class MyConstraint(object):
    pass

def constraint_mapping():
    return {"constraint1": MyConstraint}
        """
        plugin_dir = self.useFixture(fixtures.TempDir())
        plugin_file = os.path.join(plugin_dir.path, "test.py")
        with open(plugin_file, "w+") as ef:
            ef.write(constraint_content)
        self.addCleanup(sys.modules.pop, "heat.engine.plugins.test")
        cfg.CONF.set_override("plugin_dirs", plugin_dir.path)

        env = environment.Environment({})
        resources._load_global_environment(env)

        self.assertEqual("MyConstraint", env.get_constraint("constraint1").__name__)
        self.assertIs(None, env.get_constraint("no_constraint"))
예제 #17
0
    def test_constraints_registry(self):
        constraint_content = '''
class MyConstraint(object):
    pass

def constraint_mapping():
    return {"constraint1": MyConstraint}
        '''
        plugin_dir = self.useFixture(fixtures.TempDir())
        plugin_file = os.path.join(plugin_dir.path, 'test.py')
        with open(plugin_file, 'w+') as ef:
            ef.write(constraint_content)
        self.addCleanup(sys.modules.pop, "heat.engine.plugins.test")
        cfg.CONF.set_override('plugin_dirs', plugin_dir.path)

        env = environment.Environment({})
        resources._load_global_environment(env)

        self.assertEqual("MyConstraint",
                         env.get_constraint("constraint1").__name__)
        self.assertIs(None, env.get_constraint("no_constraint"))
예제 #18
0
    def test_env_multi_resources_disable(self):
        # prove we can disable resources in the global environment

        g_env_content = """
        resource_registry:
            "AWS::*":
        """
        # 1. fake an environment file
        envdir = self.useFixture(fixtures.TempDir())
        envfile = os.path.join(envdir.path, "test.yaml")
        with open(envfile, "w+") as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override("environment_dir", envdir.path)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_global_environment(g_env)

        # 3. assert our resources are now gone.
        self.assertIsNone(g_env.get_resource_info("AWS::EC2::Instance"))

        # 4. make sure we haven't removed something we shouldn't have
        self.assertEqual(server.Server, g_env.get_resource_info("OS::Nova::Server").value)
예제 #19
0
    def test_env_one_resource_disable(self):
        # prove we can disable a resource in the global environment

        g_env_content = '''
        resource_registry:
            "OS::Nova::Server":
        '''
        # 1. fake an environment file
        envdir = self.useFixture(fixtures.TempDir())
        envfile = os.path.join(envdir.path, 'test.yaml')
        with open(envfile, 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir', envdir.path)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_global_environment(g_env)

        # 3. assert our resource is in now gone.
        self.assertIsNone(g_env.get_resource_info('OS::Nova::Server'))

        # 4. make sure we haven't removed something we shouldn't have
        self.assertEqual(instance.Instance,
                         g_env.get_resource_info('AWS::EC2::Instance').value)
예제 #20
0
    def test_env_one_resource_disable(self):
        # prove we can disable a resource in the global environment

        g_env_content = '''
        resource_registry:
            "OS::Nova::Server":
        '''
        # 1. fake an environment file
        envdir = self.useFixture(fixtures.TempDir())
        envfile = os.path.join(envdir.path, 'test.yaml')
        with open(envfile, 'w+') as ef:
            ef.write(g_env_content)
        cfg.CONF.set_override('environment_dir', envdir.path)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_global_environment(g_env)

        # 3. assert our resource is in now gone.
        self.assertIsNone(g_env.get_resource_info('OS::Nova::Server'))

        # 4. make sure we haven't removed something we shouldn't have
        self.assertEqual(instance.Instance,
                         g_env.get_resource_info('AWS::EC2::Instance').value)