def _test_container_images_yaml_in_sync_helper(self,
                                                   neutron_driver=None,
                                                   remove_images=[]):
        '''Confirm overcloud_containers.tpl.yaml equals overcloud_containers.yaml

        TODO(sbaker) remove when overcloud_containers.yaml is deleted
        '''
        mod_dir = os.path.dirname(sys.modules[__name__].__file__)
        project_dir = os.path.abspath(os.path.join(mod_dir, '../../../'))
        files_dir = os.path.join(project_dir, 'container-images')

        oc_tmpl_file = os.path.join(files_dir, 'overcloud_containers.yaml.j2')
        tmpl_builder = kb.KollaImageBuilder([oc_tmpl_file])

        def ffunc(entry):
            if 'params' in entry:
                del (entry['params'])
            if 'services' in entry:
                del (entry['services'])
            return entry

        result = tmpl_builder.container_images_from_template(
            filter=ffunc, neutron_driver=neutron_driver)

        oc_yaml_file = os.path.join(files_dir, 'overcloud_containers.yaml')
        yaml_builder = kb.KollaImageBuilder([oc_yaml_file])
        container_images = yaml_builder.load_config_files(
            yaml_builder.CONTAINER_IMAGES)

        # remove image references from overcloud_containers.yaml specified
        # in remove_images param.
        for image in remove_images:
            container_images.remove(image)

        self.assertSequenceEqual(container_images, result)
Ejemplo n.º 2
0
    def run(self, context):
        def ffunc(entry):
            return entry

        template_file = os.path.join(sys.prefix, 'share', 'tripleo-common',
                                     'container-images',
                                     'overcloud_containers.yaml.j2')

        builder = kolla_builder.KollaImageBuilder([template_file])
        result = builder.container_images_from_template(filter=ffunc)

        params = {}
        for entry in result:
            imagename = entry.get('imagename', '')
            if 'params' in entry:
                for p in entry.pop('params'):
                    params[p] = imagename
        swift = self.get_object_client(context)
        try:
            swift.put_object(
                self.container, constants.CONTAINER_DEFAULTS_ENVIRONMENT,
                yaml.safe_dump({'parameter_defaults': params},
                               default_flow_style=False))
        except swiftexceptions.ClientException as err:
            err_msg = ("Error updating %s for plan %s: %s" %
                       (constants.CONTAINER_DEFAULTS_ENVIRONMENT,
                        self.container, err))
            LOG.exception(err_msg)
            return actions.Result(error=err_msg)

        environments = {constants.CONTAINER_DEFAULTS_ENVIRONMENT: True}

        update_action = heat_capabilities.UpdateCapabilitiesAction(
            environments, container=self.container)
        return update_action.run(context)
    def test_container_images_from_template_filter(self):
        builder = kb.KollaImageBuilder(self.filelist)

        def filter(entry):

            # do not want heat-agents image
            if 'heat-docker-agents' in entry.get('imagename'):
                return

            # set source and destination on all entries
            entry['push_destination'] = 'localhost:8787'
            return entry

        result = builder.container_images_from_template(filter=filter,
                                                        tag='liberty')
        container_images = [{
            'imagename': 'docker.io/tripleomaster/'
            'centos-binary-nova-compute:liberty',
            'push_destination': 'localhost:8787',
            'uploader': 'docker'
        }, {
            'imagename': 'docker.io/tripleomaster/'
            'centos-binary-nova-libvirt:liberty',
            'push_destination': 'localhost:8787',
            'uploader': 'docker'
        }, {
            'imagename': 'docker.io/tripleomaster/image-with-missing-tag',
            'push_destination': 'localhost:8787'
        }]
        self.assertEqual(container_images, result)
 def test_container_images_from_template(self):
     builder = kb.KollaImageBuilder(self.filelist)
     result = builder.container_images_from_template(
         push_destination='localhost:8787', tag='liberty')
     # template substitution on the container_images_template section should
     # be identical to the container_images section
     container_images = yaml.safe_load(filedata)['container_images']
     self.assertEqual(container_images, result)
    def test_build_images_no_conf(self, mock_popen):
        process = mock.Mock()
        process.returncode = 0
        process.communicate.return_value = 'done', ''
        mock_popen.return_value = process

        builder = kb.KollaImageBuilder([])
        self.assertEqual('done', builder.build_images([]))
        env = os.environ.copy()
        mock_popen.assert_called_once_with([
            'kolla-build',
        ],
                                           env=env,
                                           stdout=-1)
    def test_build_images_fail(self, mock_popen):
        process = mock.Mock()
        process.returncode = 1
        process.communicate.return_value = '', 'ouch'
        mock_popen.return_value = process

        builder = kb.KollaImageBuilder([])
        self.assertRaises(subprocess.CalledProcessError, builder.build_images,
                          [])
        env = os.environ.copy()
        mock_popen.assert_called_once_with([
            'kolla-build',
        ],
                                           env=env,
                                           stdout=-1)
    def test_build_images(self, mock_popen, mock_path):
        process = mock.Mock()
        process.returncode = 0
        process.communicate.return_value = 'done', ''
        mock_popen.return_value = process

        builder = kb.KollaImageBuilder(self.filelist)
        self.assertEqual('done', builder.build_images(['kolla-config.conf']))
        env = os.environ.copy()
        mock_popen.assert_called_once_with([
            'kolla-build',
            '--config-file',
            'kolla-config.conf',
            'nova-compute',
            'nova-libvirt',
            'heat-docker-agents-centos',
            'image-with-missing-tag',
        ],
                                           env=env,
                                           stdout=-1)
    def test_container_images_template_inputs(self):
        builder = kb.KollaImageBuilder(self.filelist)
        self.assertEqual(kb.CONTAINER_IMAGES_DEFAULTS,
                         builder.container_images_template_inputs())

        self.assertEqual(
            {
                'namespace': 'docker.io/tripleomaster',
                'ceph_namespace': 'docker.io/ceph',
                'ceph_image': 'daemon',
                'ceph_tag': 'tag-stable-3.0-luminous-centos-7',
                'name_prefix': 'centos-binary-',
                'name_suffix': '',
                'tag': 'current-tripleo',
                'tag_from_label': 'rdo_version',
                'neutron_driver': None
            }, builder.container_images_template_inputs())

        self.assertEqual(
            {
                'namespace': '192.0.2.0:5000/tripleomaster',
                'ceph_namespace': 'docker.io/cephh',
                'ceph_image': 'ceph-daemon',
                'ceph_tag': 'latest',
                'name_prefix': 'prefix-',
                'name_suffix': '-suffix',
                'tag': 'master',
                'tag_from_label': 'rdo_version',
                'neutron_driver': 'ovn'
            },
            builder.container_images_template_inputs(
                namespace='192.0.2.0:5000/tripleomaster',
                ceph_namespace='docker.io/cephh',
                ceph_image='ceph-daemon',
                ceph_tag='latest',
                name_prefix='prefix',
                name_suffix='suffix',
                tag='master',
                neutron_driver='ovn',
            ))