From 1243b15fce02273fdb4979e34cef4fbe73dba358 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 13 Dec 2013 15:51:17 -0800 Subject: [PATCH] Remove hard-coding of package/component names Fixes: bug #1208679 Change-Id: I90f5ec62bde4c1fd960e262f4f1556600273232d --- anvil/packaging/base.py | 44 ++++------------ anvil/packaging/yum.py | 97 +++++++++++++++-------------------- conf/components/cinder.yaml | 4 ++ conf/components/glance.yaml | 4 ++ conf/components/horizon.yaml | 3 ++ conf/components/keystone.yaml | 4 ++ conf/components/neutron.yaml | 4 ++ conf/components/nova.yaml | 4 ++ conf/distros/rhel.yaml | 6 +-- 9 files changed, 78 insertions(+), 92 deletions(-) diff --git a/anvil/packaging/base.py b/anvil/packaging/base.py index 6b407261..d4b8c9d3 100644 --- a/anvil/packaging/base.py +++ b/anvil/packaging/base.py @@ -30,32 +30,6 @@ from anvil import utils LOG = logging.getLogger(__name__) -# TODO(harlowja): get rid of static lists in code files for these names -# which we should be able to take in via configuration or other automatic -# process -OPENSTACK_PACKAGES = frozenset([ - "ceilometer", - "cinder", - "glance", - "heat", - "horizon", - "keystone", - "neutron", - "nova", - "oslo.config", - "oslo.messaging", - "python-cinderclient", - "python-glanceclient", - "python-keystoneclient", - "python-neutronclient", - "python-novaclient", - "python-swiftclient", - "python-troveclient", - "swift", - "trove", -]) -SKIP_PACKAGE_NAMES = [] - class InstallHelper(object): """Run pre and post install for a single package.""" @@ -218,16 +192,18 @@ class DependencyHandler(object): extra_pips = extra_pips or [] cmdline = [ self.multipip_executable, - "--skip-requirements-regex", - "python.*client", - "--pip", - self.pip_executable + "--pip", self.pip_executable, ] cmdline = cmdline + extra_pips + ["-r"] + requires_files - cmdline.extend(["--ignore-package"]) - cmdline.extend(OPENSTACK_PACKAGES) - cmdline.extend(SKIP_PACKAGE_NAMES) - cmdline.extend(self.python_names) + + ignore_pip_names = set(self.python_names) + more_ignores = self.distro.get_dependency_config('ignore_pip_names', + quiet=True) + if more_ignores: + ignore_pip_names.update([str(n) for n in more_ignores]) + if ignore_pip_names: + cmdline.extend(["--ignore-package"]) + cmdline.extend(ignore_pip_names) stdout, stderr = sh.execute(cmdline, check_exit_code=False) self.pips_to_install = list(utils.splitlines_not_empty(stdout)) diff --git a/anvil/packaging/yum.py b/anvil/packaging/yum.py index 19fddf57..d34759a9 100644 --- a/anvil/packaging/yum.py +++ b/anvil/packaging/yum.py @@ -61,28 +61,6 @@ class YumInstallHelper(base.InstallHelper): class YumDependencyHandler(base.DependencyHandler): OPENSTACK_EPOCH = 2 SPEC_TEMPLATE_DIR = "packaging/specs" - # TODO(harlowja): get rid of these static lists/mappings from code and move - # them to configuration (or elsewhere). - API_NAMES = { - "nova": "Compute", - "glance": "Image", - "keystone": "Identity", - "cinder": "Volume", - "neutron": "Networking", - } - SERVER_NAMES = [ - "ceilometer", - "cinder", - "glance", - "heat", - "keystone", - "neutron", - "nova", - "trove", - ] - TRANSLATION_NAMES = { - 'horizon': "python-django-horizon", - } YUM_REPO_DIR = "/etc/yum.repos.d/" SRC_REPOS = { 'anvil': 'anvil-source', @@ -519,56 +497,65 @@ class YumDependencyHandler(base.DependencyHandler): sh.gzip(archive_name) sh.unlink(archive_name) - @staticmethod - def _is_client(instance_name, egg_name): - for i in [instance_name, egg_name]: - if i and i.endswith("client"): - return True - return False - - def _get_template_and_rpm_name(self, instance): - template_name = None + def _find_template_and_rpm_name(self, instance, build_name): + search_names = [ + [ + build_name, + "%s.spec" % build_name, + ], + ] try: egg_name = instance.egg_info['name'] - if self._is_client(instance.name, egg_name): - rpm_name = egg_name - template_name = "python-commonclient.spec" - elif instance.name in self.SERVER_NAMES: - rpm_name = "openstack-%s" % (egg_name) - else: - rpm_name = self.TRANSLATION_NAMES.get(instance.name) + if any(s.endswith("client") for s in (instance.name, egg_name, build_name)): + search_names.extend([ + [ + egg_name, + "python-commonclient.spec", + ], + ]) + search_names.extend([ + [ + "openstack-%s" % (egg_name), + "openstack-%s.spec" % (egg_name), + ], + [ + egg_name, + "%s.spec" % (egg_name), + ], + ]) except AttributeError: - rpm_name = instance.name - template_name = "%s.spec" % rpm_name - return (rpm_name, template_name) + pass + + # Return the first that exists (if any from this list) + for (rpm_name, template_name) in search_names: + spec_filename = sh.joinpths(settings.TEMPLATE_DIR, + self.SPEC_TEMPLATE_DIR, template_name) + if sh.isfile(spec_filename): + return (rpm_name, template_name) + return (None, None) def _build_openstack_package(self, instance): params = self._package_parameters(instance) patches = instance.list_patches("package") params['patches'] = [sh.basename(fn) for fn in patches] - (rpm_name, template_name) = self._get_template_and_rpm_name(instance) + + build_name = instance.get_option('build_name', default_value=instance.name) + (rpm_name, template_name) = self._find_template_and_rpm_name(instance, build_name) try: egg_name = instance.egg_info['name'] params["version"] = instance.egg_info["version"] - if self._is_client(instance.name, egg_name): + if any(s.endswith("client") for s in (instance.name, egg_name, build_name)): client_name = utils.strip_prefix_suffix(egg_name, "python-", "client") if not client_name: msg = "Bad client package name %s" % (egg_name) raise excp.PackageException(msg) params["clientname"] = client_name - params["apiname"] = self.API_NAMES.get(client_name, - client_name.title()) + params["apiname"] = instance.get_option('api_name', + default_value=client_name.title()) except AttributeError: - spec_filename = None - if template_name: - spec_filename = sh.joinpths(settings.TEMPLATE_DIR, - self.SPEC_TEMPLATE_DIR, - template_name) - if not spec_filename or not sh.isfile(spec_filename): - rpm_name = None - if rpm_name: - if not template_name: - template_name = "%s.spec" % rpm_name + pass + + if all((rpm_name, template_name)): spec_filename = self._write_spec_file(instance, rpm_name, template_name, params) self._build_from_spec(instance, spec_filename, patches) diff --git a/conf/components/cinder.yaml b/conf/components/cinder.yaml index dd2ae8e7..3357306e 100644 --- a/conf/components/cinder.yaml +++ b/conf/components/cinder.yaml @@ -6,4 +6,8 @@ api_host: "$(auto:ip)" api_port: 8776 protocol: http +# Used for associating the client package with a human understandable +# name in its package description (not a code-name, like cinder). +api_name: "Volume" + ... diff --git a/conf/components/glance.yaml b/conf/components/glance.yaml index 95b224fa..c3e38728 100644 --- a/conf/components/glance.yaml +++ b/conf/components/glance.yaml @@ -29,4 +29,8 @@ image_cache_dir: "/usr/share/anvil/glance/images" # Used by install section in the specfile (conflicts with the client binary...) remove_file: "/bin/rm -rf %{buildroot}/usr/bin/glance" +# Used for associating the client package with a human understandable +# name in its package description (not a code-name, like glance). +api_name: "Image" + ... diff --git a/conf/components/horizon.yaml b/conf/components/horizon.yaml index bd7ca4a2..ff37f712 100644 --- a/conf/components/horizon.yaml +++ b/conf/components/horizon.yaml @@ -1,4 +1,7 @@ # Settings for component horizon --- +# Instead of naming this components package horizon, it will be named this instead +build_name: "python-django-horizon" + ... diff --git a/conf/components/keystone.yaml b/conf/components/keystone.yaml index 66b93267..25b3abe2 100644 --- a/conf/components/keystone.yaml +++ b/conf/components/keystone.yaml @@ -11,6 +11,10 @@ service_host: "$(auto:ip)" service_port: 5000 service_proto: http +# Used for associating the client package with a human understandable +# name in its package description (not a code-name, like keystone). +api_name: "Identity" + # Test exclusions... # # TODO(harlowja) these should probably be bugs... diff --git a/conf/components/neutron.yaml b/conf/components/neutron.yaml index 99eac875..de06b1bd 100644 --- a/conf/components/neutron.yaml +++ b/conf/components/neutron.yaml @@ -6,6 +6,10 @@ api_host: "$(auto:ip)" api_port: 9696 protocol: http +# Used for associating the client package with a human understandable +# name in its package description (not a code-name, like neutron). +api_name: "Networking" + core_plugin: openvswitch use_namespaces: True diff --git a/conf/components/nova.yaml b/conf/components/nova.yaml index aaf7fab6..db79cad1 100644 --- a/conf/components/nova.yaml +++ b/conf/components/nova.yaml @@ -117,6 +117,10 @@ vncserver_listen: 127.0.0.1 vncserver_proxyclient_address: "" xvpvncproxy_url: "http://$(auto:ip):6081/console" +# Used for associating the client package with a human understandable +# name in its package description (not a code-name, like nova). +api_name: "Compute" + # Test exclusions... # # TODO(harlowja) these should probably be bugs... diff --git a/conf/distros/rhel.yaml b/conf/distros/rhel.yaml index 946c25ec..7cb3414d 100644 --- a/conf/distros/rhel.yaml +++ b/conf/distros/rhel.yaml @@ -24,9 +24,9 @@ dependency_handler: qpid-python: python-qpid # Why is this one backwards :-/ PyYAML: PyYAML arch_dependent: - - selenium - - xattr - - PuLP + - selenium + - xattr + - PuLP commands: service: restart: service $NAME restart