update bigtop repo handling (#43) #46

Merged
merged 1 commit into from Sep 7, 2016
Jump to file or symbol
Failed to load files and symbols.
+46 −24
Split
View
@@ -23,8 +23,10 @@ defines:
bigtop_version:
type: string
- default: 'bigtop-1.1.0'
- description: 'Default version string of Bigtop release. Affects the location of Hiera bits and Puppet recipes'
+ default: '1.1.0'
+ description: |
+ Bigtop release version. Affects the location of Hiera bits, Puppet
+ recipes, and repository used for installing packages.
bigtop_release_url:
type: string
@@ -34,30 +36,30 @@ defines:
This points to the official Apache Bigtop releases on of the ASF mirrors.
The source code is needed in order to get access to project's Puppet recipes
- bigtop_repo-x86_64:
- type: string
- default: 'http://bigtop-repos.s3.amazonaws.com/releases/1.1.0/ubuntu/trusty/x86_64'
- description: URL to release apt repo for x86_64 platform
-
- bigtop_repo-ppc64el:
+ bigtop_repo_url:
type: string
- default: 'http://bigtop-repos.s3.amazonaws.com/releases/1.1.0/ubuntu/vivid/ppc64el'
- description: URL to release apt repo for ppc64el platform
+ default: 'http://bigtop-repos.s3.amazonaws.com/releases/{version}/{dist}/{series}/{arch}'
+ description: |
+ Apache Bigtop repo URL used to install Bigtop packages. The version
+ dist, series, and arch will be substituted based on the platform and
+ configuration at deployment time. You may specify a URL that omits
+ these special keys; they will be ignored if not present during
+ substitution.
- bigtop_hiera_path:
+ bigtop_global_hiera:
type: string
default: '/etc/puppet/hiera.yaml'
description: 'Hiera global configuration file'
bigtop_hiera_config:
type: string
default: 'bigtop-deploy/puppet/hiera.yaml'
- description: 'Hiera Bigtop config'
+ description: 'Hiera Bigtop config file, relative to the bigtop src dir'
bigtop_hiera_siteyaml:
type: string
default: 'bigtop-deploy/puppet/hieradata/site.yaml'
- description: 'Hiera Bigtop config'
+ description: 'Hiera Bigtop site yaml, relative to the bigotp src dir'
bigtop_smoketest_components:
type: array
@@ -1,4 +1,5 @@
import os
+import platform
import socket
import subprocess
import yaml
@@ -39,12 +40,32 @@ def site_yaml(self):
def __init__(self):
self.bigtop_dir = '/home/ubuntu/bigtop.release'
self.options = layer.options('apache-bigtop-base')
- self.bigtop_version = self.options.get('bigtop_version')
- self.bigtop_apt = self.options.get(
- 'bigtop_repo-{}'.format(utils.cpu_arch()))
- self._bigtop_base = Path(self.bigtop_dir) / self.bigtop_version
- self._site_yaml = self.bigtop_base / self.options.get(
- 'bigtop_hiera_siteyaml')
+ self.bigtop_version = self.options['bigtop_version']
+ self._bigtop_base = Path(self.bigtop_dir) / 'bigtop-{}'.format(
+ self.bigtop_version)
+ self._site_yaml = Path(self.bigtop_base) / self.options[
+ 'bigtop_hiera_siteyaml']
@petevg

petevg Sep 2, 2016

If we're going to fail hard on key errors for options, I'd prefer to see us raise a custom exceptions. Something like BigtopConfigError. That way, the person troubleshooting isn't stuck tracking down cryptic KeyErrors in the code.

Also, this will melt the tests -- you'll need to replace the mock object with a dict with mock values in the setUp for each test class.

@johnsca

johnsca Sep 2, 2016

Owner

These values are coming from layer.yaml which supports validation to ensure the values are provided, so I don't think we need to worry about the KeyError here (though we should confirm that the properties are defined as required).

@kwmonroe

kwmonroe Sep 2, 2016

Member

@johnsca, this silently failed for me:

        self.bigtop_apt = self.options.get(
            'bigtop_repo-{}'.format(utils.cpu_arch()))

because cpu_arch returns 'ppc64le' on power, and we had the option set as 'ppc64el', so .get('nonexistent') just came back blank.

+
+ dist_name, _, dist_series = platform.linux_distribution()
@johnsca

johnsca Sep 2, 2016

Owner

This will work, but it's actually deprecated for versions of Python later than what's on Xenial. We could change it later, but charmhelpers.core.host.lsb_release() can give you the series as well.

+ # NB: xenial repo is not currently available, and ppc64le only works
+ # with vivid. Force vivid on ppc and trusty on everyone else for now:
+ # http://paste.ubuntu.com/18185418/
+ repo_arch = utils.cpu_arch()
+ if repo_arch == "ppc64le":
+ dist_series = "vivid"
+ # The 'le' and 'el' are swapped due to historical debian awfulness.
+ # https://lists.debian.org/debian-powerpc/2014/08/msg00042.html
+ repo_arch = "ppc64el"
+ else:
+ dist_series = "trusty"
@ktsakalozos

ktsakalozos Sep 2, 2016

Member

Just merged the Xenial only PR. Is this line still valid?

@kwmonroe

kwmonroe Sep 2, 2016

Member

Yes, even though our OS is now xenial-only, the repo that we use to install bigtop-1.1.0 only offers "trusty" for x86 and "vivid" for ppc64le. I assume this will change once 1.2.0 is released and bigtop offers official xenial repos.

+ # Substitute params in the configured option. It's ok if any of these
+ # params (version, dist, series, arch) are missing.
+ self.bigtop_apt = self.options['bigtop_repo_url'].format(
+ version=self.bigtop_version,
+ dist=dist_name.lower(),
+ series=dist_series.lower(),
+ arch=repo_arch
+ )
def get_ip_for_interface(self, network_interface):
"""
@@ -96,7 +117,6 @@ def pin_bigtop_packages(self):
"""
Tell Ubuntu to use the Bigtop repo where possible, so that we
don't actually fetch newer packages from universe.
-
"""
origin = urlparse(self.bigtop_apt).netloc
@@ -120,7 +140,7 @@ def check_reverse_dns(self):
def fetch_bigtop_release(self):
# download Bigtop release; unpack the recipes
- bigtop_url = self.options.get('bigtop_release_url')
+ bigtop_url = self.options['bigtop_release_url']
Path(self.bigtop_dir).rmtree_p()
au = ArchiveUrlFetchHandler()
au.install(bigtop_url, self.bigtop_dir)
@@ -132,16 +152,16 @@ def install_puppet_modules(self):
def apply_patches(self):
charm_dir = Path(hookenv.charm_dir())
- for patch in sorted(glob('resources/{}/*.patch'.format(self.bigtop_version))):
+ for patch in sorted(glob('resources/bigtop-{}/*.patch'.format(self.bigtop_version))):
with chdir("{}".format(self.bigtop_base)):
utils.run_as('root', 'patch', '-p1', '-s', '-i', charm_dir / patch)
def render_hiera_yaml(self):
"""
Render the ``hiera.yaml`` file with the correct path to our ``site.yaml`` file.
"""
- hiera_src = self.bigtop_base / self.options.get('bigtop_hiera_config')
- hiera_dst = Path(self.options.get('bigtop_hiera_path'))
+ hiera_src = Path(self.bigtop_base) / self.options['bigtop_hiera_config']
+ hiera_dst = Path(self.options['bigtop_global_hiera'])
# read template defaults
hiera_yaml = yaml.load(hiera_src.text())