Exemplo n.º 1
0
def main(argv=None):

    if argv is None:
        argv = sys.argv

    service.prepare_service(argv)

    if cfg.CONF.master_seed and not cfg.CONF.resource_registry:
        sys.stderr.write("When using `master-seed` you must also specify "
                         "`resource-registry`.")
        sys.exit(1)

    all_roles, created, updated = load_roles(
        cfg.CONF.role,
        seed_file=cfg.CONF.master_seed,
        resource_registry_path=cfg.CONF.resource_registry,
        role_extra=cfg.CONF.role_extra)

    if len(created):
        _print_names("Created", created)

    if len(updated):
        _print_names("Updated", updated)

    print("Imported {0} roles".format(len(all_roles)))
Exemplo n.º 2
0
    def test_import_seed_and_registry(self):
        env_data = """
resource_registry:
  OS::TripleO::Role: role1.yaml
  OS::TripleO::Another: required_file.yaml
  OS::TripleO::SoftwareDeployment: OS::Heat::StructuredDeployment
        """

        # Setup
        self._create_file(path.join(self.directory, 'seed'))
        self._create_file(path.join(self.directory, 'environment'), env_data)
        self._create_file(path.join(self.directory, 'required_file.yaml'))

        # Test
        seed_file = path.join(self.directory, 'seed')
        env_file = path.join(self.directory, 'environment')
        all_roles, created, updated = load_roles.load_roles(
            self.roles, seed_file=seed_file, resource_registry_path=env_file)

        # Verify
        self.assertEqual(['_master_seed', '_registry', 'role1', 'role2'],
                         sorted(all_roles))
        self.assertEqual([
            '_master_seed', '_registry', 'required_file.yaml', 'role1', 'role2'
        ], sorted(created))
        self.assertEqual([], updated)

        # Check resource registry
        registry_list = ResourceRegistryMappingStore().list()
        ordered_list = sorted(registry_list, key=lambda x: x.name)
        self.assertEqual('OS::Heat::StructuredDeployment',
                         ordered_list[0].name)
        self.assertEqual('required_file.yaml', ordered_list[1].name)
Exemplo n.º 3
0
    def test_import_seed_and_registry(self):
        env_data = """
resource_registry:
  OS::TripleO::Role: role1.yaml
  OS::TripleO::Another: required_file.yaml
  OS::TripleO::SoftwareDeployment: OS::Heat::StructuredDeployment
        """

        # Setup
        self._create_file(path.join(self.directory, 'seed'))
        self._create_file(path.join(self.directory, 'environment'), env_data)
        self._create_file(path.join(self.directory, 'required_file.yaml'))

        # Test
        seed_file = path.join(self.directory, 'seed')
        env_file = path.join(self.directory, 'environment')
        all_roles, created, updated = load_roles.load_roles(
            self.roles,
            seed_file=seed_file,
            resource_registry_path=env_file)

        # Verify
        self.assertEqual(['_master_seed', '_registry',
                          'role1', 'role2'], sorted(all_roles))
        self.assertEqual(['_master_seed', '_registry', 'required_file.yaml',
                          'role1', 'role2'], sorted(created))
        self.assertEqual([], updated)

        # Check resource registry
        registry_list = ResourceRegistryMappingStore().list()
        ordered_list = sorted(registry_list, key=lambda x: x.name)
        self.assertEqual('OS::Heat::StructuredDeployment',
                         ordered_list[0].name)
        self.assertEqual('required_file.yaml',
                         ordered_list[1].name)
Exemplo n.º 4
0
def main(argv=None):

    if argv is None:
        argv = sys.argv

    service.prepare_service(argv)

    if cfg.CONF.master_seed and not cfg.CONF.resource_registry:
        sys.stderr.write("When using `master-seed` you must also specify "
                         "`resource-registry`.")
        sys.exit(1)

    all_roles, created, updated = load_roles(
        cfg.CONF.role,
        seed_file=cfg.CONF.master_seed,
        resource_registry_path=cfg.CONF.resource_registry,
        role_extra=cfg.CONF.role_extra)

    if len(created):
        _print_names("Created", created)

    if len(updated):
        _print_names("Updated", updated)

    print("Imported {0} roles".format(len(all_roles)))
Exemplo n.º 5
0
    def test_import(self):

        # test
        total, created, updated = load_roles.load_roles(self.roles)

        # verify
        self.assertEqual(['role1', 'role2'], sorted(total))
        self.assertEqual(['role1', 'role2'], sorted(created))
        self.assertEqual([], updated)
Exemplo n.º 6
0
    def test_import(self):

        # test
        total, created, updated = load_roles(self.directory)

        # verify
        self.assertEqual(['role1.yaml', 'role2.yml'], sorted(total))
        self.assertEqual(['role1.yaml', 'role2.yml'], sorted(created))
        self.assertEqual([], updated)
Exemplo n.º 7
0
    def test_import(self):

        # test
        total, created, updated = load_roles.load_roles(self.roles)

        # verify
        self.assertEqual(['role1', 'role2'], sorted(total))
        self.assertEqual(['role1', 'role2'], sorted(created))
        self.assertEqual([], updated)
Exemplo n.º 8
0
    def test_dry_run(self):

        # test
        total, created, updated = load_roles(
            self.directory, dry_run=True)

        # verify
        self.assertEqual(['role1.yaml', 'role2.yml'], sorted(total))
        self.assertEqual([], created)
        self.assertEqual([], updated)
Exemplo n.º 9
0
    def test_dry_run(self):

        # test
        total, created, updated = load_roles.load_roles(
            self.roles, dry_run=True)

        # verify
        self.assertEqual(['role1', 'role2'], sorted(total))
        self.assertEqual([], created)
        self.assertEqual([], updated)
Exemplo n.º 10
0
    def test_import_update(self):

        # setup
        _create_or_update("role2.yml", "contents")

        # test
        total, created, updated = load_roles(self.directory)

        # verify
        self.assertEqual(['role1.yaml', 'role2.yml'], sorted(total))
        self.assertEqual(['role1.yaml', ], created)
        self.assertEqual(['role2.yml', ], updated)
Exemplo n.º 11
0
    def test_import_update(self):

        # setup
        load_roles._create_or_update("role2", "contents")

        # test
        total, created, updated = load_roles.load_roles(self.roles)

        # verify
        self.assertEqual(['role1', 'role2'], sorted(total))
        self.assertEqual(['role1', ], created)
        self.assertEqual(['role2', ], updated)
Exemplo n.º 12
0
    def test_import_update(self):

        # setup
        load_utils.create_or_update("role2", "contents")

        # test
        total, created, updated = load_roles.load_roles(self.roles)

        # verify
        self.assertEqual(['role1', 'role2'], sorted(total))
        self.assertEqual(['role1', ], created)
        self.assertEqual(['role2', ], updated)
Exemplo n.º 13
0
    def test_import_with_seed(self):
        # Setup
        self._create_file(path.join(self.directory, 'seed'))

        # Test
        seed_file = path.join(self.directory, 'seed')
        total, created, updated = load_roles.load_roles(self.roles,
                                                        seed_file=seed_file)

        # Verify
        self.assertEqual(['_master_seed', 'role1', 'role2'], sorted(total))
        self.assertEqual(['_master_seed', 'role1', 'role2'], sorted(created))
        self.assertEqual([], updated)
Exemplo n.º 14
0
    def test_import_with_seed(self):
        # Setup
        self._create_file(path.join(self.directory, 'seed'))

        # Test
        seed_file = path.join(self.directory, 'seed')
        total, created, updated = load_roles.load_roles(self.roles,
                                                        seed_file=seed_file)

        # Verify
        self.assertEqual(['_master_seed', 'role1', 'role2'], sorted(total))
        self.assertEqual(['_master_seed', 'role1', 'role2'], sorted(created))
        self.assertEqual([], updated)
Exemplo n.º 15
0
def main(argv=None):

    if argv is None:
        argv = sys.argv

    service.prepare_service(argv)

    all_roles, created, updated = load_roles(cfg.CONF.directory,
                                             cfg.CONF.dry_run)

    if len(created):
        _print_names("Created", created)

    if len(updated):
        _print_names("Updated", updated)

    if not cfg.CONF.dry_run:
        print("Imported {0} roles".format(len(all_roles)))
    else:
        _print_names("Found", all_roles)
        print("Imported 0 roles")