diff --git a/hammer.py b/hammer.py index 57647e9747..1c39d3d0f9 100755 --- a/hammer.py +++ b/hammer.py @@ -42,36 +42,50 @@ SYSTEMS = { #'27', # EOLed #'28', # EOLed #'29', # EOLed - '30', # EOLed - '31', - '32', - '33'], - 'centos': ['7', '8'], + #'30', # EOLed + #'31', # EOLed + '32', # EOLed + '33', + '34', + ], + 'centos': [ + '7', + '8', + ], 'rhel': ['8'], 'ubuntu': [ #'16.04', '18.04', #'18.10', # EOLed #'19.04', # EOLed - '19.10', + #'19.10', # EOLed '20.04', - '20.10'], - 'debian': [#'8', - '9', - '10'], - 'freebsd': ['11.2', - '11.4', - '12.0', - '12.1'], + '20.10', + '21.04', + ], + 'debian': [ + #'8', + '9', + '10', + ], + 'freebsd': [ + '11.2', + '11.4', + '12.0', + '12.1', + '13.0', + ], 'alpine': [ - '3.10', + #'3.10', # EOLed '3.11', - '3.12' + '3.12', + '3.13', ] } # pylint: disable=C0326 IMAGE_TEMPLATES = { + # fedora 'fedora-27-lxc': {'bare': 'lxc-fedora-27', 'kea': 'godfryd/kea-fedora-27'}, 'fedora-27-virtualbox': {'bare': 'generic/fedora27', 'kea': 'godfryd/kea-fedora-27'}, 'fedora-28-lxc': {'bare': 'godfryd/lxc-fedora-28', 'kea': 'godfryd/kea-fedora-28'}, @@ -84,11 +98,18 @@ IMAGE_TEMPLATES = { 'fedora-31-virtualbox': {'bare': 'isc/vbox-fedora-31', 'kea': 'isc/kea-fedora-31'}, 'fedora-32-lxc': {'bare': 'isc/lxc-fedora-32', 'kea': 'isc/kea-fedora-32'}, 'fedora-33-lxc': {'bare': 'isc/lxc-fedora-33', 'kea': 'isc/kea-fedora-33'}, + 'fedora-34-lxc': {'bare': 'isc/lxc-fedora-34', 'kea': 'isc/kea-fedora-34'}, + + # centos 'centos-7-lxc': {'bare': 'godfryd/lxc-centos-7', 'kea': 'isc/kea-centos-7'}, 'centos-7-virtualbox': {'bare': 'generic/centos7', 'kea': 'godfryd/kea-centos-7'}, 'centos-8-lxc': {'bare': 'isc/lxc-centos-8', 'kea': 'isc/kea-centos-8'}, 'centos-8-virtualbox': {'bare': 'generic/centos8', 'kea': 'isc/kea-centos-8'}, + + # rhel 'rhel-8-virtualbox': {'bare': 'generic/rhel8', 'kea': 'generic/rhel8'}, + + # ubuntu 'ubuntu-16.04-lxc': {'bare': 'godfryd/lxc-ubuntu-16.04', 'kea': 'godfryd/kea-ubuntu-16.04'}, 'ubuntu-16.04-virtualbox': {'bare': 'ubuntu/xenial64', 'kea': 'godfryd/kea-ubuntu-16.04'}, 'ubuntu-18.04-lxc': {'bare': 'godfryd/lxc-ubuntu-18.04', 'kea': 'godfryd/kea-ubuntu-18.04'}, @@ -101,17 +122,26 @@ IMAGE_TEMPLATES = { 'ubuntu-19.10-virtualbox': {'bare': 'generic/ubuntu1910', 'kea': 'isc/kea-ubuntu-19.10'}, 'ubuntu-20.04-lxc': {'bare': 'isc/lxc-ubuntu-20.04', 'kea': 'isc/kea-ubuntu-20.04'}, 'ubuntu-20.10-lxc': {'bare': 'isc/lxc-ubuntu-20.10', 'kea': 'isc/kea-ubuntu-20.10'}, + 'ubuntu-21.04-lxc': {'bare': 'isc/lxc-ubuntu-21.04', 'kea': 'isc/kea-ubuntu-21.04'}, + + # debian 'debian-8-lxc': {'bare': 'godfryd/lxc-debian-8', 'kea': 'godfryd/kea-debian-8'}, 'debian-8-virtualbox': {'bare': 'debian/jessie64', 'kea': 'godfryd/kea-debian-8'}, 'debian-9-lxc': {'bare': 'godfryd/lxc-debian-9', 'kea': 'godfryd/kea-debian-9'}, 'debian-9-virtualbox': {'bare': 'debian/stretch64', 'kea': 'godfryd/kea-debian-9'}, 'debian-10-lxc': {'bare': 'godfryd/lxc-debian-10', 'kea': 'godfryd/kea-debian-10'}, 'debian-10-virtualbox': {'bare': 'debian/buster64', 'kea': 'godfryd/kea-debian-10'}, + + # freebsd 'freebsd-11.2-virtualbox': {'bare': 'generic/freebsd11', 'kea': 'godfryd/kea-freebsd-11.2'}, 'freebsd-12.0-virtualbox': {'bare': 'generic/freebsd12', 'kea': 'godfryd/kea-freebsd-12.0'}, + 'freebsd-13.0-virtualbox': {'bare': 'isc/vbox-freebsd-13.0', 'kea': 'isc/kea-freebsd-13.0'}, + + # alpine 'alpine-3.10-lxc': {'bare': 'godfryd/lxc-alpine-3.10', 'kea': 'godfryd/kea-alpine-3.10'}, 'alpine-3.11-lxc': {'bare': 'isc/lxc-alpine-3.11', 'kea': 'isc/kea-alpine-3.11'}, 'alpine-3.12-lxc': {'bare': 'isc/lxc-alpine-3.12', 'kea': 'isc/kea-alpine-3.12'}, + 'alpine-3.13-lxc': {'bare': 'isc/lxc-alpine-3.13', 'kea': 'isc/kea-alpine-3.13'}, } # NOTES @@ -485,11 +515,6 @@ class VagrantEnv(object): self.nofeatures_arg = None self.python = None - if provider == "virtualbox": - vagrantfile_tpl = VBOX_VAGRANTFILE_TPL - elif provider == "lxc": - vagrantfile_tpl = LXC_VAGRANTFILE_TPL - self.key = key = "%s-%s-%s" % (system, revision, provider) self.image_tpl = image_tpl = IMAGE_TEMPLATES[key][image_template_variant] self.repo_dir = os.getcwd() @@ -500,28 +525,25 @@ class VagrantEnv(object): elif provider == "lxc": self.vagrant_dir = os.path.join(self.repo_dir, 'hammer', sys_dir, 'lxc') - if dry_run: - return + if ccache_dir is None: + self.ccache_dir = '/' + self.ccache_enabled = False + else: + self.ccache_dir = ccache_dir + self.ccache_enabled = True + self.init_files() + + def init_files(self): if not os.path.exists(self.vagrant_dir): os.makedirs(self.vagrant_dir) vagrantfile_path = os.path.join(self.vagrant_dir, "Vagrantfile") - if os.path.exists(vagrantfile_path): - # TODO: destroy any existing VM - pass - crc = binascii.crc32(self.vagrant_dir.encode()) - self.name = "hmr-%s-%s-kea-srv-%08d" % (system, revision.replace('.', '-'), crc) + self.name = "hmr-%s-%s-kea-srv-%08d" % (self.system, self.revision.replace('.', '-'), crc) - if ccache_dir is None: - ccache_dir = '/' - self.ccache_enabled = False - else: - self.ccache_enabled = True - - if '/' in image_tpl: + if '/' in self.image_tpl: self.latest_version = self._get_latest_cloud_version() box_version = 'config.vm.box_version = "%s"' % self.latest_version else: @@ -529,14 +551,19 @@ class VagrantEnv(object): box_version = "" # alpine has a problem with setting hostname so skip it - if system == 'alpine': + if self.system == 'alpine': hostname = '' else: hostname = 'config.vm.hostname = "%s"' % self.name - vagrantfile = vagrantfile_tpl.format(image_tpl=image_tpl, + if self.provider == "virtualbox": + vagrantfile_tpl = VBOX_VAGRANTFILE_TPL + elif self.provider == "lxc": + vagrantfile_tpl = LXC_VAGRANTFILE_TPL + + vagrantfile = vagrantfile_tpl.format(image_tpl=self.image_tpl, name=self.name, - ccache_dir=ccache_dir, + ccache_dir=self.ccache_dir, box_version=box_version, hostname=hostname) @@ -612,6 +639,9 @@ class VagrantEnv(object): Status can be: 'not created', 'running', 'stopped', etc. """ + if not os.path.exists(self.vagrant_dir): + return "not created" + _, out = execute("vagrant status", cwd=self.vagrant_dir, timeout=15, capture=True, quiet=True) m = re.search('default\s+(.+)\(', out) if not m: @@ -700,7 +730,7 @@ class VagrantEnv(object): latest_version = self._get_latest_cloud_version(image_tpl) new_version = latest_version + 1 - cmd = "vagrant cloud publish -f -r %s %s %s %s" + cmd = "vagrant cloud publish --no-private -f -r %s %s %s %s" cmd = cmd % (image_tpl, new_version, self.provider, box_path) execute(cmd, cwd=self.vagrant_dir, timeout=60 * 60) @@ -827,9 +857,10 @@ class VagrantEnv(object): def destroy(self): """Remove the VM completely.""" - cmd = 'vagrant destroy --force' - execute(cmd, cwd=self.vagrant_dir, timeout=3 * 60, dry_run=self.dry_run) # timeout: 3 minutes - execute('rm -rf %s', self.vagrant_dir) + if os.path.exists(self.vagrant_dir): + cmd = 'vagrant destroy --force' + execute(cmd, cwd=self.vagrant_dir, timeout=3 * 60, dry_run=self.dry_run) # timeout: 3 minutes + execute('rm -rf %s' % self.vagrant_dir) def ssh(self): """Open interactive session to the VM.""" @@ -866,17 +897,23 @@ class VagrantEnv(object): else: self.nofeatures_arg = '' - # install python3 for centos 8 + # install python3 on some systems if self.system == 'centos': if self.revision == '7': self.execute("sudo yum remove -y python-devel") self.execute("sudo yum install -y python36 rpm-build python3-virtualenv", attempts=3) else: self.execute("sudo dnf install -y python36 rpm-build python3-virtualenv", attempts=3) + elif self.system == 'freebsd': + if self.revision.startswith('13'): + self.execute("sudo pkg install -y python3", attempts=3) # select proper python version for running Hammer inside Vagrant system if self.system == 'freebsd': - self.python = 'python3.6' + if self.revision.startswith(('11', '12')): + self.python = 'python3.6' + else: + self.python = 'python3' else: self.python = 'python3' @@ -922,29 +959,31 @@ class VagrantEnv(object): log.info('') def prepare_for_boxing(self): - if self.system not in ['debian', 'ubuntu', 'fedora', 'centos', 'rhel']: - return + if self.system in ['debian', 'ubuntu', 'fedora', 'centos', 'rhel']: + # setup a script that on first boot will set machine-id + cmd = 'bash -c \'cat <