Remove hard-coding of package/component names
Fixes: bug #1208679 Change-Id: I90f5ec62bde4c1fd960e262f4f1556600273232d
This commit is contained in:
committed by
Ivan A. Melnikov
parent
326d59009a
commit
1243b15fce
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user