diff -Nru rax-nova-agent-2.1.15/debian/changelog rax-nova-agent-2.1.18/debian/changelog --- rax-nova-agent-2.1.15/debian/changelog 2018-08-24 17:45:45.000000000 +0000 +++ rax-nova-agent-2.1.18/debian/changelog 2018-11-21 12:58:53.000000000 +0000 @@ -1,3 +1,15 @@ +rax-nova-agent (2.1.18-0ubuntu1) disco; urgency=medium + + * New upstream version 2.1.18 (LP: #1804445) + - Update _setup_hostname to write to /etc/hostname file when failing + on hostnamectl. Move function to base class since function is the + same for all operating systems + - Update tests to ensure changes to _setup_hostname are covered + * Clean up after rax-openstack-guest-agents in postinst + * Refresh patches + + -- Balint Reczey Wed, 21 Nov 2018 13:58:53 +0100 + rax-nova-agent (2.1.15-0ubuntu2) cosmic; urgency=medium * Drop dependency on python3-systemd, it is not needed with latest upstream diff -Nru rax-nova-agent-2.1.15/debian/patches/0004-Use-DefaultDependencies-no-to-prevent-forming-servic.patch rax-nova-agent-2.1.18/debian/patches/0004-Use-DefaultDependencies-no-to-prevent-forming-servic.patch --- rax-nova-agent-2.1.15/debian/patches/0004-Use-DefaultDependencies-no-to-prevent-forming-servic.patch 2018-08-24 17:45:45.000000000 +0000 +++ rax-nova-agent-2.1.18/debian/patches/0004-Use-DefaultDependencies-no-to-prevent-forming-servic.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -From: Balint Reczey -Date: Fri, 24 Aug 2018 19:27:47 +0200 -Subject: Use DefaultDependencies=no to prevent forming service ordering cycles - -LP: #1788716 ---- - etc/nova-agent.service | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/etc/nova-agent.service b/etc/nova-agent.service -index 76e05e2..8e7af93 100644 ---- a/etc/nova-agent.service -+++ b/etc/nova-agent.service -@@ -1,5 +1,6 @@ - [Unit] - Description=Nova Agent for xenstore -+DefaultDependencies=no - Wants=cloud-init-local.service - Before=network-online.target - Before=cloud-init.service diff -Nru rax-nova-agent-2.1.15/debian/patches/after-proc-xen.patch rax-nova-agent-2.1.18/debian/patches/after-proc-xen.patch --- rax-nova-agent-2.1.15/debian/patches/after-proc-xen.patch 2018-08-24 17:45:45.000000000 +0000 +++ rax-nova-agent-2.1.18/debian/patches/after-proc-xen.patch 2018-11-21 12:58:53.000000000 +0000 @@ -1,10 +1,18 @@ -Description: Ensure agent is started after /proc/xen is mounted. - This ensures that /proc/xen/xenbus is available, and one can use that - via pyxs, instead of forking to xenstore-* utilities. +From: Balint Reczey +Date: Fri, 24 Aug 2018 19:25:59 +0200 +Subject: Ensure agent is started after /proc/xen is mounted. +This ensures that /proc/xen/xenbus is available, and one can use that +via pyxs, instead of forking to xenstore-* utilities. +--- + etc/nova-agent.service | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/etc/nova-agent.service b/etc/nova-agent.service +index a50f9d6..8e7af93 100644 --- a/etc/nova-agent.service +++ b/etc/nova-agent.service -@@ -5,6 +5,8 @@ +@@ -6,6 +6,8 @@ Before=network-online.target Before=cloud-init.service After=xe-daemon.service Requires=xe-daemon.service diff -Nru rax-nova-agent-2.1.15/debian/patches/bring-up-xe-daemon.patch rax-nova-agent-2.1.18/debian/patches/bring-up-xe-daemon.patch --- rax-nova-agent-2.1.15/debian/patches/bring-up-xe-daemon.patch 2018-08-24 17:45:45.000000000 +0000 +++ rax-nova-agent-2.1.18/debian/patches/bring-up-xe-daemon.patch 2018-11-21 12:58:53.000000000 +0000 @@ -1,8 +1,16 @@ +From: Balint Reczey +Date: Fri, 24 Aug 2018 19:25:59 +0200 +Subject: bring-up-xe-daemon + +--- + etc/nova-agent.service | 2 ++ + 1 file changed, 2 insertions(+) + diff --git a/etc/nova-agent.service b/etc/nova-agent.service -index 735ef66..c441e75 100644 +index ff3c44f..a50f9d6 100644 --- a/etc/nova-agent.service +++ b/etc/nova-agent.service -@@ -3,6 +3,8 @@ Description=Nova Agent for xenstore +@@ -4,6 +4,8 @@ DefaultDependencies=no Wants=cloud-init-local.service Before=network-online.target Before=cloud-init.service diff -Nru rax-nova-agent-2.1.15/debian/patches/series rax-nova-agent-2.1.18/debian/patches/series --- rax-nova-agent-2.1.15/debian/patches/series 2018-08-24 17:45:45.000000000 +0000 +++ rax-nova-agent-2.1.18/debian/patches/series 2018-11-21 12:58:53.000000000 +0000 @@ -1,4 +1,3 @@ skip_failing_netplan_tests.patch bring-up-xe-daemon.patch after-proc-xen.patch -0004-Use-DefaultDependencies-no-to-prevent-forming-servic.patch diff -Nru rax-nova-agent-2.1.15/debian/patches/skip_failing_netplan_tests.patch rax-nova-agent-2.1.18/debian/patches/skip_failing_netplan_tests.patch --- rax-nova-agent-2.1.15/debian/patches/skip_failing_netplan_tests.patch 2018-08-24 17:45:45.000000000 +0000 +++ rax-nova-agent-2.1.18/debian/patches/skip_failing_netplan_tests.patch 2018-11-21 12:58:53.000000000 +0000 @@ -11,10 +11,10 @@ 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/tests_libs_debian.py b/tests/tests_libs_debian.py -index 39a804c..718db0c 100644 +index c09d1ce..f8b109d 100644 --- a/tests/tests_libs_debian.py +++ b/tests/tests_libs_debian.py -@@ -71,7 +71,7 @@ class TestHelpers(TestCase): +@@ -89,7 +89,7 @@ class TestHelpers(TestCase): 'Written file did not match expected value' ) @@ -23,7 +23,7 @@ self.setup_temp_hostname() self.setup_temp_interfaces() temp = debian.ServerOS() -@@ -154,7 +154,7 @@ class TestHelpers(TestCase): +@@ -172,7 +172,7 @@ class TestHelpers(TestCase): 'Written file did not match expected value' ) @@ -32,7 +32,7 @@ self.setup_temp_hostname() self.setup_temp_interfaces() temp = debian.ServerOS() -@@ -209,7 +209,7 @@ class TestHelpers(TestCase): +@@ -227,7 +227,7 @@ class TestHelpers(TestCase): 'Incorrect number of interface files' ) @@ -41,7 +41,7 @@ self.setup_temp_hostname() self.setup_temp_interfaces() temp = debian.ServerOS() -@@ -268,7 +268,7 @@ class TestHelpers(TestCase): +@@ -286,7 +286,7 @@ class TestHelpers(TestCase): 'Incorrect number of interface files' ) @@ -50,7 +50,7 @@ self.setup_temp_hostname() self.setup_temp_interfaces() temp = debian.ServerOS() -@@ -328,7 +328,7 @@ class TestHelpers(TestCase): +@@ -346,7 +346,7 @@ class TestHelpers(TestCase): 'Incorrect number of interface files' ) diff -Nru rax-nova-agent-2.1.15/debian/rax-nova-agent.postinst rax-nova-agent-2.1.18/debian/rax-nova-agent.postinst --- rax-nova-agent-2.1.15/debian/rax-nova-agent.postinst 1970-01-01 00:00:00.000000000 +0000 +++ rax-nova-agent-2.1.18/debian/rax-nova-agent.postinst 2018-11-21 12:58:53.000000000 +0000 @@ -0,0 +1,41 @@ +#!/bin/sh +# see: dh_installdeb(1) + +set -e + +# summary of how this script can be called: +# * `configure' +# * `abort-upgrade' +# * `abort-remove' `in-favour' +# +# * `abort-remove' +# * `abort-deconfigure' `in-favour' +# `removing' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + +case "$1" in + configure) + if dpkg --compare-versions "$2" lt "2.1.15-0ubuntu1~16.04.0~" && [ -d /run/systemd/system ]; then + # nova-resetnetwork.service is not shipped anymore but leaves + # .wants symlink behind + if deb-systemd-helper --quiet was-enabled nova-resetnetwork.service; then + env _DEB_SYSTEMD_HELPER_PURGE=1 deb-systemd-helper disable nova-resetnetwork.service >/dev/null || true + fi + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# diff -Nru rax-nova-agent-2.1.15/etc/nova-agent.service rax-nova-agent-2.1.18/etc/nova-agent.service --- rax-nova-agent-2.1.15/etc/nova-agent.service 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/etc/nova-agent.service 2018-09-13 17:22:04.000000000 +0000 @@ -1,5 +1,6 @@ [Unit] Description=Nova Agent for xenstore +DefaultDependencies=no Wants=cloud-init-local.service Before=network-online.target Before=cloud-init.service diff -Nru rax-nova-agent-2.1.15/novaagent/common/file_inject.py rax-nova-agent-2.1.18/novaagent/common/file_inject.py --- rax-nova-agent-2.1.15/novaagent/common/file_inject.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/common/file_inject.py 2018-09-13 17:22:04.000000000 +0000 @@ -17,7 +17,8 @@ """ JSON File injection plugin """ -from __future__ import print_function + +from __future__ import absolute_import from novaagent.utils import encode_to_bytes diff -Nru rax-nova-agent-2.1.15/novaagent/common/kms.py rax-nova-agent-2.1.18/novaagent/common/kms.py --- rax-nova-agent-2.1.15/novaagent/common/kms.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/common/kms.py 2018-09-13 17:22:04.000000000 +0000 @@ -18,8 +18,6 @@ """ redhat/centos KMS activation helper module """ -from __future__ import print_function - import subprocess import logging @@ -133,7 +131,7 @@ update_files = configure_up2date(domains) with open(UP2DATE_PATH, 'w') as up2date: - print(update_files[UP2DATE_PATH], file=up2date) + up2date.write(update_files[UP2DATE_PATH]) message = register_with_rhn(activation_key, profile) if message: diff -Nru rax-nova-agent-2.1.15/novaagent/__init__.py rax-nova-agent-2.1.18/novaagent/__init__.py --- rax-nova-agent-2.1.15/novaagent/__init__.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/__init__.py 2018-09-13 17:22:04.000000000 +0000 @@ -1,2 +1,2 @@ -__version__ = '2.1.15' +__version__ = '2.1.18' diff -Nru rax-nova-agent-2.1.15/novaagent/libs/centos.py rax-nova-agent-2.1.18/novaagent/libs/centos.py --- rax-nova-agent-2.1.15/novaagent/libs/centos.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/libs/centos.py 2018-09-13 17:22:04.000000000 +0000 @@ -1,5 +1,4 @@ -from __future__ import print_function from __future__ import absolute_import @@ -21,11 +20,11 @@ class ServerOS(DefaultOS): def __init__(self): + super(ServerOS, self).__init__() self.netconfig_dir = '/etc/sysconfig/network-scripts' + self.network_file = '/etc/sysconfig/network' self.interface_file_prefix = 'ifcfg' self.route_file_prefix = 'route' - self.hostname_file = '/etc/hostname' - self.network_file = '/etc/sysconfig/network' def _setup_interface(self, ifname, iface): interface_file = '{0}/{1}-{2}'.format( @@ -110,14 +109,17 @@ known_settings = [ '^BOOTPROTO=', '^DEVICE=', '^GATEWAY=', '^IPV6INIT=', '^IPV6ADDR=', '^IPV6_DEFAULTGW=', '^ONBOOT=', '^NM_CONTROLLED=', '^DNS\d+?=', - '^IPADDR\d+?=', '^NETMASK\d+?=', '^#', '^\s+' + '^IPADDR\d?', '^NETMASK\d?', '^#', '^\s+' ] log.debug('Checking for additional arguments for ifcfg') pattern = re.compile('|'.join(known_settings)) - with open(interface_file, 'r') as file: - for line in file: - if not pattern.search(line): - add_args.append(line.strip()) + + # File will not exist on initial boot so check and make sure exists + if os.path.isfile(interface_file): + with open(interface_file, 'r') as file: + for line in file: + if not pattern.search(line): + add_args.append(line.strip()) log.debug( 'Found {0} extra arguments to ' @@ -153,37 +155,6 @@ ) ) - def _setup_hostname(self, client): - hostname = utils.get_hostname(client) - completed = False - if os.path.exists('/usr/bin/hostnamectl'): - utils.backup_file(self.hostname_file) - p = Popen( - ['hostnamectl', 'set-hostname', hostname], - stdout=PIPE, - stderr=PIPE, - stdin=PIPE - ) - out, err = p.communicate() - if p.returncode != 0: - log.error('Error using hostnamectl: {0}'.format(err)) - else: - # Do not run hostname since it was successful - completed = True - - if not completed: - p = Popen( - ['hostname', hostname], - stdout=PIPE, - stderr=PIPE, - stdin=PIPE - ) - out, err = p.communicate() - if p.returncode != 0: - log.error('Error using hostname: {0}'.format(err)) - - return p.returncode, hostname - def resetnetwork(self, name, value, client): ifaces = {} hostname_return_code, hostname = self._setup_hostname(client) diff -Nru rax-nova-agent-2.1.15/novaagent/libs/debian.py rax-nova-agent-2.1.18/novaagent/libs/debian.py --- rax-nova-agent-2.1.15/novaagent/libs/debian.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/libs/debian.py 2018-09-13 17:22:04.000000000 +0000 @@ -1,5 +1,4 @@ -from __future__ import print_function from __future__ import absolute_import @@ -22,9 +21,9 @@ class ServerOS(DefaultOS): def __init__(self): + super(ServerOS, self).__init__() self.netplan_file = '/etc/netplan/rackspace-cloud.yaml' self.netconfig_file = '/etc/network/interfaces' - self.hostname_file = '/etc/hostname' def _setup_loopback(self): with open(self.netconfig_file, 'w') as iffile: @@ -32,40 +31,6 @@ iffile.write('auto lo\n') iffile.write('iface lo inet loopback\n\n') - def _setup_hostname(self, client): - """ - hostnamectl is available in some Debian systems and depends on dbus - """ - hostname = utils.get_hostname(client) - completed = False - if os.path.exists('/usr/bin/hostnamectl'): - utils.backup_file(self.hostname_file) - p = Popen( - ['hostnamectl', 'set-hostname', hostname], - stdout=PIPE, - stderr=PIPE, - stdin=PIPE - ) - out, err = p.communicate() - if p.returncode != 0: - log.error('Error using hostnamectl: {0}'.format(err)) - else: - # Do not run hostname since it was successful - completed = True - - if not completed: - p = Popen( - ['hostname', hostname], - stdout=PIPE, - stderr=PIPE, - stdin=PIPE - ) - out, err = p.communicate() - if p.returncode != 0: - log.error('Error using hostname: {0}'.format(err)) - - return p.returncode - def _setup_interfaces(self, ifname, iface): with open(self.netconfig_file, 'a') as iffile: iffile.write('# Label {0}\n'.format(iface['label'])) @@ -211,7 +176,7 @@ def resetnetwork(self, name, value, client): ifaces = {} - hostname_return_code = self._setup_hostname(client) + hostname_return_code, _ = self._setup_hostname(client) if hostname_return_code != 0: log.error('Error setting hostname on system') diff -Nru rax-nova-agent-2.1.15/novaagent/libs/__init__.py rax-nova-agent-2.1.18/novaagent/libs/__init__.py --- rax-nova-agent-2.1.15/novaagent/libs/__init__.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/libs/__init__.py 2018-09-13 17:22:04.000000000 +0000 @@ -2,14 +2,29 @@ from __future__ import absolute_import +import logging +import os + + +from subprocess import PIPE +from subprocess import Popen + + import novaagent from novaagent.common.password import PasswordCommands from novaagent.common.file_inject import FileInject +from novaagent import utils + + +log = logging.getLogger(__name__) class DefaultOS(object): + def __init__(self): + self.hostname_file = '/etc/hostname' + def keyinit(self, name, value, client): if not hasattr(self, 'p'): self.p = PasswordCommands() @@ -37,3 +52,42 @@ def version(self, name, value, client): return ('0', str(novaagent.__version__)) + + """ + Common function for all operating systems when setting up hostname + """ + def _setup_hostname(self, client): + hostname = utils.get_hostname(client) + completed = False + if os.path.exists('/usr/bin/hostnamectl'): + utils.backup_file(self.hostname_file) + p = Popen( + ['hostnamectl', 'set-hostname', hostname], + stdout=PIPE, + stderr=PIPE, + stdin=PIPE + ) + out, err = p.communicate() + if p.returncode != 0: + log.error('Error using hostnamectl: {0}'.format(err)) + else: + # Do not run hostname since hostnamectl was successful + completed = True + + if not completed: + log.debug('Falling back to use hostname command') + p = Popen( + ['hostname', hostname], + stdout=PIPE, + stderr=PIPE, + stdin=PIPE + ) + out, err = p.communicate() + if p.returncode != 0: + log.error('Error using hostname: {0}'.format(err)) + else: + log.debug('Writing file {0}'.format(self.hostname_file)) + with open(self.hostname_file, 'w') as host_file: + host_file.write(hostname) + + return p.returncode, hostname diff -Nru rax-nova-agent-2.1.15/novaagent/libs/redhat.py rax-nova-agent-2.1.18/novaagent/libs/redhat.py --- rax-nova-agent-2.1.15/novaagent/libs/redhat.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/libs/redhat.py 2018-09-13 17:22:04.000000000 +0000 @@ -1,5 +1,4 @@ -from __future__ import print_function from __future__ import absolute_import diff -Nru rax-nova-agent-2.1.15/novaagent/novaagent.py rax-nova-agent-2.1.18/novaagent/novaagent.py --- rax-nova-agent-2.1.15/novaagent/novaagent.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/novaagent.py 2018-09-13 17:22:04.000000000 +0000 @@ -1,5 +1,4 @@ -from __future__ import print_function from __future__ import absolute_import diff -Nru rax-nova-agent-2.1.15/novaagent/utils.py rax-nova-agent-2.1.18/novaagent/utils.py --- rax-nova-agent-2.1.15/novaagent/utils.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/novaagent/utils.py 2018-09-13 17:22:04.000000000 +0000 @@ -1,5 +1,7 @@ from __future__ import absolute_import + + from socket import error as socket_error diff -Nru rax-nova-agent-2.1.15/README.md rax-nova-agent-2.1.18/README.md --- rax-nova-agent-2.1.15/README.md 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/README.md 2018-09-13 17:22:04.000000000 +0000 @@ -1,4 +1,38 @@ [![Travis Status](https://travis-ci.org/Rackspace-DOT/nova-agent.svg?branch=master)](https://travis-ci.org/Rackspace-DOT/nova-agent.svg?branch=master) -# nova agent +# Rackspace nova-agent + +Running agent that helps with the setup of the server initially on first boot, and allows for password and network changes during the life cycle of the server. + +#### Requirements + +The agent will check and make sure that the instance is running on Rackspace hosts, and if so it will continue running and complete any tasks that is being requested through xenstore. If it is not then the agent will immediately stop running log the reason. + +The agent will also look and see if `/dev/xen/xenbus` is available, and if so will utilize [pyxs](https://github.com/selectel/pyxs) library to interact with xenstore. If it is not available then the agent will try and utilize xenstore commands that are provided by xenstore-utils. + +#### What does the agent do? + +##### Networking + * RHEL based systems use ifcfg scripts that are located in `/etc/sysconfig/network-scripts` + + **Note:** If extra options are placed in the ifcfg scripts scripts such as ZONE for firewalld. Then when networking is reset or IP addresses are added/removed those configuration options will be preserved by the agent. + + * Debian based systems use the `/etc/network/interfaces` file and sets them up accordingly. + + * Ubuntu based systems that utilize netplan will have networking setup in the following location: `/etc/netplan/rackspace-cloud.yaml` + + You can learn more about netplan here [https://netplan.io/](https://netplan.io/) and is available on Rackspace cloud in the Ubuntu 18.04 base image. + +##### Hostname + * On all systems the agent will try and use `hostnamectl` to set the hostname. If that fails then the agent will fall back and use the `hostname` command, and write to the `/etc/hostname` so that the hostname persists through a reboot. + +##### Password + * Sets the password assigned to the server on initial boot by nova. Also allows for password changes initiated by a user during the life cycle of the server + +##### RHEL registration + * For RHEL servers the agent completes RHN registration for the server on initial boot + +#### Compatability + +The agent is currently python 2.6 - 3.6 compatible, and Travis CI is being utilized for testing all python versions. diff -Nru rax-nova-agent-2.1.15/tests/tests_init.py rax-nova-agent-2.1.18/tests/tests_init.py --- rax-nova-agent-2.1.15/tests/tests_init.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/tests/tests_init.py 2018-09-13 17:22:04.000000000 +0000 @@ -29,7 +29,7 @@ def test_version(self): self.assertEqual( novaagent.__version__, - '2.1.15', + '2.1.18', 'Version expected was not returned correctly' ) @@ -37,7 +37,7 @@ temp = libs.DefaultOS() self.assertEqual( temp.version('Name', 'Value', 'Client'), - ('0', '2.1.15'), + ('0', '2.1.18'), 'Did not get expected value on version' ) diff -Nru rax-nova-agent-2.1.15/tests/tests_libs_centos.py rax-nova-agent-2.1.18/tests/tests_libs_centos.py --- rax-nova-agent-2.1.15/tests/tests_libs_centos.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/tests/tests_libs_centos.py 2018-09-13 17:22:04.000000000 +0000 @@ -47,6 +47,7 @@ def setup_temp_interface_config(self, interface): with open('/tmp/ifcfg-{0}'.format(interface), 'a+') as f: f.write( + 'IPADDR=2.2.2.2\n' 'IPADDR999=1.1.1.1\n' 'ZONE=TestFirewalldZone\n' '# Comment in file\n' @@ -57,7 +58,7 @@ def setup_temp_hostname(self): with open('/tmp/hostname', 'a+') as f: - f.write('This is a test file') + f.write('test.hostname.local') def setup_temp_network(self): with open('/tmp/network', 'a+') as f: @@ -102,7 +103,7 @@ with mock.patch( 'novaagent.libs.centos.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 1, 'test_hostname' + hostname.return_value = 1, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -183,7 +184,7 @@ with mock.patch( 'novaagent.libs.centos.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -276,7 +277,7 @@ with mock.patch( 'novaagent.libs.centos.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -357,7 +358,7 @@ with mock.patch( 'novaagent.libs.centos.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -440,7 +441,7 @@ with mock.patch( 'novaagent.libs.centos.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch( 'novaagent.utils.list_xenstore_macaddrs' ) as mac: @@ -530,7 +531,7 @@ with mock.patch( 'novaagent.libs.centos.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch( 'novaagent.utils.list_xenstore_macaddrs' ) as mac: @@ -618,6 +619,22 @@ 'Did not get proper extra arguments from check' ) + def test_check_extra_args_no_file(self): + temp = centos.ServerOS() + interface_file = '/tmp/ifcfg-eth1' + + extra_args = temp._check_for_extra_settings(interface_file) + self.assertEqual( + len(extra_args), + 0, + 'Did not get proper number of arguments from check' + ) + self.assertEqual( + extra_args, + [], + 'Did not get proper extra arguments from check' + ) + def test_setup_routes(self): self.setup_temp_route() temp = centos.ServerOS() @@ -693,9 +710,9 @@ test_hostname = 'test.hostname' with mock.patch('novaagent.utils.get_hostname') as hostname: hostname.return_value = test_hostname - with mock.patch('novaagent.libs.centos.os.path.exists') as exists: + with mock.patch('novaagent.libs.os.path.exists') as exists: exists.return_value = False - with mock.patch('novaagent.libs.centos.Popen') as popen: + with mock.patch('novaagent.libs.Popen') as popen: popen.return_value.communicate.return_value = ( ('out', 'err') ) @@ -722,9 +739,9 @@ test_hostname = 'test.hostname' with mock.patch('novaagent.utils.get_hostname') as hostname: hostname.return_value = test_hostname - with mock.patch('novaagent.libs.centos.os.path.exists') as exists: + with mock.patch('novaagent.libs.os.path.exists') as exists: exists.return_value = False - with mock.patch('novaagent.libs.centos.Popen') as popen: + with mock.patch('novaagent.libs.Popen') as popen: popen.return_value.communicate.return_value = ( ('out', 'err') ) @@ -751,9 +768,9 @@ test_hostname = 'test.hostname' with mock.patch('novaagent.utils.get_hostname') as hostname: hostname.return_value = test_hostname - with mock.patch('novaagent.libs.centos.os.path.exists') as exists: + with mock.patch('novaagent.libs.os.path.exists') as exists: exists.return_value = True - with mock.patch('novaagent.libs.centos.Popen') as popen: + with mock.patch('novaagent.libs.Popen') as popen: popen.return_value.communicate.return_value = ( ('out', 'err') ) @@ -780,9 +797,9 @@ test_hostname = 'test.hostname' with mock.patch('novaagent.utils.get_hostname') as hostname: hostname.return_value = test_hostname - with mock.patch('novaagent.libs.centos.os.path.exists') as exists: + with mock.patch('novaagent.libs.os.path.exists') as exists: exists.return_value = True - with mock.patch('novaagent.libs.centos.Popen') as popen: + with mock.patch('novaagent.libs.Popen') as popen: popen.return_value.communicate.return_value = ( ('out', 'err') ) diff -Nru rax-nova-agent-2.1.15/tests/tests_libs_debian.py rax-nova-agent-2.1.18/tests/tests_libs_debian.py --- rax-nova-agent-2.1.15/tests/tests_libs_debian.py 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/tests/tests_libs_debian.py 2018-09-13 17:22:04.000000000 +0000 @@ -46,7 +46,7 @@ def setup_temp_hostname(self): with open('/tmp/hostname', 'a+') as f: - f.write('This is a test file') + f.write('test.hostname.local') def setup_temp_interfaces(self): with open('/tmp/interfaces', 'a+') as f: @@ -56,6 +56,24 @@ with open('/tmp/rackspace-cloud.yaml', 'a+') as f: f.write('#This is a test file\n') + def test_initialization(self): + temp = debian.ServerOS() + self.assertEqual( + temp.netplan_file, + '/etc/netplan/rackspace-cloud.yaml', + 'Initialized netplan file value does not match expected value' + ) + self.assertEqual( + temp.netconfig_file, + '/etc/network/interfaces', + 'Initialized netconfig file value does not match expected value' + ) + self.assertEqual( + temp.hostname_file, + '/etc/hostname', + 'Initialized hostname file value does not match expected value' + ) + def test_setup_loopback(self): temp = debian.ServerOS() temp.netconfig_file = '/tmp/interfaces' @@ -80,7 +98,7 @@ with mock.patch( 'novaagent.libs.debian.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 1 + hostname.return_value = 1, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E207572', 'BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -163,7 +181,7 @@ with mock.patch( 'novaagent.libs.debian.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -218,7 +236,7 @@ with mock.patch( 'novaagent.libs.debian.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -277,7 +295,7 @@ with mock.patch( 'novaagent.libs.debian.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0, 'test_hostname' + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -337,7 +355,7 @@ with mock.patch( 'novaagent.libs.debian.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0 + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E207572', 'BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -465,7 +483,7 @@ with mock.patch( 'novaagent.libs.debian.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0 + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E207572', 'BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -541,7 +559,7 @@ with mock.patch( 'novaagent.libs.debian.ServerOS._setup_hostname' ) as hostname: - hostname.return_value = 0 + hostname.return_value = 0, 'temp.hostname' with mock.patch('novaagent.utils.list_xenstore_macaddrs') as mac: mac.return_value = ['BC764E207572', 'BC764E206C5B'] with mock.patch('novaagent.utils.list_hw_interfaces') as hwint: @@ -601,14 +619,14 @@ test_hostname = 'test.hostname' with mock.patch('novaagent.utils.get_hostname') as hostname: hostname.return_value = test_hostname - with mock.patch('novaagent.libs.debian.os.path.exists') as exists: + with mock.patch('novaagent.libs.os.path.exists') as exists: exists.return_value = False - with mock.patch('novaagent.libs.debian.Popen') as popen: + with mock.patch('novaagent.libs.Popen') as popen: popen.return_value.communicate.return_value = ( ('out', 'err') ) popen.return_value.returncode = 0 - return_code = temp._setup_hostname( + return_code, _ = temp._setup_hostname( 'dummy_client' ) @@ -618,29 +636,15 @@ 'Return code received was not expected value' ) - def test_setup_hostname_hostname_failure(self): - self.setup_temp_hostname() - temp = debian.ServerOS() - temp.hostname_file = '/tmp/hostname' - test_hostname = 'test.hostname' - with mock.patch('novaagent.utils.get_hostname') as hostname: - hostname.return_value = test_hostname - with mock.patch('novaagent.libs.debian.os.path.exists') as exists: - exists.return_value = False - with mock.patch('novaagent.libs.debian.Popen') as popen: - popen.return_value.communicate.return_value = ( - ('out', 'err') - ) - popen.return_value.returncode = 1 - return_code = temp._setup_hostname( - 'dummy_client' - ) + with open('/tmp/hostname') as f: + written_data = f.readlines() - self.assertEqual( - return_code, - 1, - 'Return code received was not expected value' - ) + for index, line in enumerate(written_data): + self.assertEqual( + line, + test_hostname, + 'Did not find expected hostname in file' + ) def test_setup_hostname_hostnamectl_success(self): self.setup_temp_hostname() @@ -649,14 +653,14 @@ test_hostname = 'test.hostname' with mock.patch('novaagent.utils.get_hostname') as hostname: hostname.return_value = test_hostname - with mock.patch('novaagent.libs.debian.os.path.exists') as exists: + with mock.patch('novaagent.libs.os.path.exists') as exists: exists.return_value = True - with mock.patch('novaagent.libs.debian.Popen') as popen: + with mock.patch('novaagent.libs.Popen') as popen: popen.return_value.communicate.return_value = ( ('out', 'err') ) popen.return_value.returncode = 0 - return_code = temp._setup_hostname( + return_code, _ = temp._setup_hostname( 'dummy_client' ) @@ -673,14 +677,14 @@ test_hostname = 'test.hostname' with mock.patch('novaagent.utils.get_hostname') as hostname: hostname.return_value = test_hostname - with mock.patch('novaagent.libs.debian.os.path.exists') as exists: + with mock.patch('novaagent.libs.os.path.exists') as exists: exists.return_value = True - with mock.patch('novaagent.libs.debian.Popen') as popen: + with mock.patch('novaagent.libs.Popen') as popen: popen.return_value.communicate.return_value = ( ('out', 'err') ) popen.return_value.returncode = 1 - return_code = temp._setup_hostname( + return_code, _ = temp._setup_hostname( 'dummy_client' ) diff -Nru rax-nova-agent-2.1.15/.travis.yml rax-nova-agent-2.1.18/.travis.yml --- rax-nova-agent-2.1.15/.travis.yml 2018-07-23 15:34:25.000000000 +0000 +++ rax-nova-agent-2.1.18/.travis.yml 2018-09-13 17:22:04.000000000 +0000 @@ -6,9 +6,10 @@ - "3.4" - "3.5" - "3.6" + - "3.7-dev" install: - pip install -e .[tests] before_script: - flake8 . script: - - nosetests -v --cover-erase --with-coverage --cover-package=novaagent + - nosetests -v