Patch basic_deploymeny.py for juju 2.7 compat

Essentially, Juju 2.7 changed the semantics of "juju run" in a way that
breaks Amulet.  Amulet is no longer supported, and this charm will have
its tests migrated to zaza in the near future.  This patch just
monkey-patches the file_contents() method of Amulet's Sentry() class so
that the memcache verify test can pass.

Change-Id: I046d9ee5fda4ca15a5824650d8aceb5d24741d94
This commit is contained in:
Alex Kavanagh 2019-11-22 11:27:09 +00:00
parent ccf1a833f7
commit 11483d5efb
1 changed files with 29 additions and 5 deletions

View File

@ -13,9 +13,11 @@
# limitations under the License.
import amulet
import functools
import json
import tempfile
import mock
import os
import tempfile
from charmhelpers.contrib.openstack.amulet.deployment import (
OpenStackAmuletDeployment
@ -53,6 +55,22 @@ class NovaOpenStackAmuletUtils(OpenStackAmuletUtils):
u = NovaOpenStackAmuletUtils(DEBUG)
def _file_contents(unit, filename):
"""Get the contents of ``filename`` on the remote unit.
Note, for Juju 2.7 compat, this function uses juju ssh instead
:param str filename: Path of file to stat on the remote unit.
:raises: IOError if the call fails.
:return: File contents as string.
"""
output, return_code = unit.ssh('sudo cat {}'.format(filename))
if return_code == 0:
return output
else:
raise IOError(output)
class NovaCCBasicDeployment(OpenStackAmuletDeployment):
"""Amulet tests on a basic nova cloud controller deployment."""
@ -455,10 +473,16 @@ class NovaCCBasicDeployment(OpenStackAmuletDeployment):
amulet.raise_status(amulet.FAIL, msg=message)
def test_110_memcache(self):
u.validate_memcache(self.nova_cc_sentry,
'/etc/nova/nova.conf',
self._get_openstack_release(),
earliest_release=self.trusty_mitaka)
# Juju 2.7 breaks unit.run, so we need to patch file_contents with an
# alternative function for this test. This is because Amulet is no
# longer maintained.
with mock.patch.object(self.nova_cc_sentry, 'file_contents',
new=functools.partial(_file_contents,
self.nova_cc_sentry)):
u.validate_memcache(self.nova_cc_sentry,
'/etc/nova/nova.conf',
self._get_openstack_release(),
earliest_release=self.trusty_mitaka)
def test_200_nova_cc_shared_db_relation(self):
"""Verify the nova-cc to mysql shared-db relation data"""