예제 #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)

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

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

        # 4. make sure we haven't removed something we shouldn't have
        self.assertEqual(resources.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.resources.open',
                        mock.mock_open(read_data=g_env_content),
                        create=True) as m_open:
            resources._load_all(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_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.resources.open", mock.mock_open(read_data=g_env_content), create=True) as m_open:
            resources._load_all(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)
예제 #4
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_all(g_env)

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

        # 4. make sure we haven't removed something we shouldn't have
        self.assertEqual(resources.server.Server,
                         g_env.get_resource_info('OS::Nova::Server').value)
예제 #5
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_all(env)

        self.assertEqual("MyConstraint", env.get_constraint("constraint1").__name__)
        self.assertIs(None, env.get_constraint("no_constraint"))
예제 #6
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_all(env)

        self.assertEqual("MyConstraint",
                         env.get_constraint("constraint1").__name__)
        self.assertIs(None, env.get_constraint("no_constraint"))
예제 #7
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_all(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(resources.instance.Instance, g_env.get_resource_info("AWS::EC2::Instance").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)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_all(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_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)

        # 2. load global env
        g_env = environment.Environment({}, user_env=False)
        resources._load_all(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)