From 3f103442d3f40387633b90445b062e9fdd8ebf91 Mon Sep 17 00:00:00 2001 From: Bilal Baqar Date: Mon, 24 Aug 2015 09:24:20 -0700 Subject: [PATCH] Improvments in Makefile and Amulets --- Makefile | 14 +++++++++----- README.ex => README.md | 2 +- hooks/pg_gw_context.py | 6 ++++-- hooks/pg_gw_utils.py | 7 +++++-- tests/{14-juno => 14-kilo} | 16 +--------------- unit_tests/test_pg_gw_context.py | 11 +++++++---- unit_tests/test_pg_gw_hooks.py | 3 +-- unit_tests/test_pg_gw_utils.py | 10 +++++----- 8 files changed, 33 insertions(+), 36 deletions(-) rename README.ex => README.md (98%) rename tests/{14-juno => 14-kilo} (64%) diff --git a/Makefile b/Makefile index bf78ed9..c89fd2f 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,18 @@ #!/usr/bin/make PYTHON := /usr/bin/env python -lint: - @flake8 --exclude hooks/charmhelpers hooks - @flake8 --exclude hooks/charmhelpers unit_tests +virtualenv: + virtualenv .venv + .venv/bin/pip install flake8 nose coverage mock pyyaml netifaces \ + netaddr jinja2 + +lint: virtualenv + .venv/bin/flake8 --exclude hooks/charmhelpers hooks unit_tests tests @charm proof -unit_test: +unit_test: virtualenv @echo Starting tests... - @$(PYTHON) /usr/bin/nosetests --nologcapture unit_tests + @.venv/bin/nosetests --nologcapture --with-coverage unit_tests bin/charm_helpers_sync.py: @mkdir -p bin diff --git a/README.ex b/README.md similarity index 98% rename from README.ex rename to README.md index a62e28c..8688e71 100644 --- a/README.ex +++ b/README.md @@ -6,7 +6,7 @@ Once deployed the charm triggers the necessary services for a PLUMgrid Gateway a # Usage -Step by step instructions on using the charm: +Instructions on using the charm: juju deploy neutron-api juju deploy neutron-api-plumgrid diff --git a/hooks/pg_gw_context.py b/hooks/pg_gw_context.py index 5eac712..6cb6b46 100644 --- a/hooks/pg_gw_context.py +++ b/hooks/pg_gw_context.py @@ -1,6 +1,7 @@ # Copyright (c) 2015, PLUMgrid Inc, http://plumgrid.com -# This file contains the class that generates context for PLUMgrid template files. +# This file contains the class that generates context for +# PLUMgrid template files. from charmhelpers.core.hookenv import ( relation_ids, @@ -52,7 +53,8 @@ class PGGwContext(context.NeutronContext): def pg_ctxt(self): ''' - Generated Config for all PLUMgrid templates inside the templates folder. + Generated Config for all PLUMgrid templates inside the + templates folder. ''' pg_ctxt = super(PGGwContext, self).pg_ctxt() if not pg_ctxt: diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index 496a447..930cc11 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py @@ -100,7 +100,9 @@ def ensure_files(): ''' Ensures PLUMgrid specific files exist before templates are written. ''' - write_file(SUDOERS_CONF, "\nnova ALL=(root) NOPASSWD: /opt/pg/bin/ifc_ctl_pp *\n", owner='root', group='root', perms=0o644) + write_file(SUDOERS_CONF, + "\nnova ALL=(root) NOPASSWD: /opt/pg/bin/ifc_ctl_pp *\n", + owner='root', group='root', perms=0o644) def restart_pg(): @@ -133,7 +135,8 @@ def remove_iovisor(): ''' Removes iovisor kernel module. ''' - _exec_cmd(cmd=['rmmod', 'iovisor'], error_msg='Error Loading Iovisor Kernel Module') + _exec_cmd(cmd=['rmmod', 'iovisor'], + error_msg='Error Loading Iovisor Kernel Module') def check_interface_type(): diff --git a/tests/14-juno b/tests/14-kilo similarity index 64% rename from tests/14-juno rename to tests/14-kilo index a808aef..ab7652f 100755 --- a/tests/14-juno +++ b/tests/14-kilo @@ -9,7 +9,7 @@ class TestDeployment(unittest.TestCase): def setUpClass(cls): cls.deployment = amulet.Deployment(series='trusty') cls.deployment.load_bundle_file( - bundle_file='files/plumgrid-gateway.yaml', + bundle_file='tests/files/plumgrid-gateway.yaml', deployment_name='test') try: cls.deployment.setup(timeout=2000) @@ -21,20 +21,6 @@ class TestDeployment(unittest.TestCase): except: raise - def test_plumgrid_gateway_external_interface(self): - pg_sentry = self.deployment.sentry['plumgrid-gateway/0'] - pg_options = self.deployment.services['plumgrid-gateway']['options'] - external_interface = pg_options['external-interface'] - if not external_interface: - amulet.raise_status( - amulet.FAIL, - msg='plumgrid external-interface parameter was not found.') - output, code = pg_sentry.run("ethtool {}".format(external_interface)) - if code != 0: - amulet.raise_status( - amulet.FAIL, - msg='external interface not found on the host') - def test_plumgrid_gateway_started(self): pg_sentry = self.deployment.sentry['plumgrid-gateway/0'] agent_state = pg_sentry.info['agent-state'] diff --git a/unit_tests/test_pg_gw_context.py b/unit_tests/test_pg_gw_context.py index 4a16521..0ca70df 100644 --- a/unit_tests/test_pg_gw_context.py +++ b/unit_tests/test_pg_gw_context.py @@ -34,13 +34,16 @@ class PGGwContextTest(CharmTestCase): @patch.object(charmhelpers.contrib.openstack.context, 'config') @patch.object(charmhelpers.contrib.openstack.context, 'unit_private_ip') @patch.object(charmhelpers.contrib.openstack.context, 'unit_get') - @patch.object(charmhelpers.contrib.openstack.context, 'config_flags_parser') + @patch.object(charmhelpers.contrib.openstack.context, + 'config_flags_parser') @patch.object(context.PGGwContext, '_save_flag_file') @patch.object(context, '_pg_dir_settings') - @patch.object(charmhelpers.contrib.openstack.context, 'neutron_plugin_attribute') + @patch.object(charmhelpers.contrib.openstack.context, + 'neutron_plugin_attribute') @patch.object(utils, 'check_interface_type') - def test_neutroncc_context_api_rel(self, _int_type, _npa, _pg_dir_settings, _save_flag_file, - _config_flag, _unit_get, _unit_priv_ip, _config, + def test_neutroncc_context_api_rel(self, _int_type, _npa, _pg_dir_settings, + _save_flag_file, _config_flag, + _unit_get, _unit_priv_ip, _config, _is_clus, _https, _ens_pkgs): def mock_npa(plugin, section, manager): if section == "driver": diff --git a/unit_tests/test_pg_gw_hooks.py b/unit_tests/test_pg_gw_hooks.py index 5965375..bebdb9d 100644 --- a/unit_tests/test_pg_gw_hooks.py +++ b/unit_tests/test_pg_gw_hooks.py @@ -39,8 +39,7 @@ class PGGwHooksTests(CharmTestCase): def setUp(self): super(PGGwHooksTests, self).setUp(hooks, TO_PATCH) - - #self.config.side_effect = self.test_config.get + # self.config.side_effect = self.test_config.get hooks.hooks._config_save = False def _call_hook(self, hookname): diff --git a/unit_tests/test_pg_gw_utils.py b/unit_tests/test_pg_gw_utils.py index 7baf2a6..366e44e 100644 --- a/unit_tests/test_pg_gw_utils.py +++ b/unit_tests/test_pg_gw_utils.py @@ -31,7 +31,7 @@ class TestPGGwUtils(CharmTestCase): def setUp(self): super(TestPGGwUtils, self).setUp(nutils, TO_PATCH) - #self.config.side_effect = self.test_config.get + # self.config.side_effect = self.test_config.get def tearDown(self): # Reset cached cache @@ -50,10 +50,10 @@ class TestPGGwUtils(CharmTestCase): self.os_release.return_value = 'trusty' templating.OSConfigRenderer.side_effect = _mock_OSConfigRenderer _regconfs = nutils.register_configs() - confs = ['/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/plumgrid.conf', - '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hostname', - '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hosts', - '/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/ifcs.conf'] + confs = [nutils.PG_CONF, + nutils.PG_HN_CONF, + nutils.PG_HS_CONF, + nutils.PG_IFCS_CONF] self.assertItemsEqual(_regconfs.configs, confs) def test_resource_map(self):