From 1071b9940b4e114cd2eabf290b739f92fbab33de Mon Sep 17 00:00:00 2001 From: Wesley Wiedenmeier Date: Sun, 28 Aug 2016 17:56:17 -0500 Subject: Improve module documentation and doc cleanup. This adds lots of config module documentation in a standard format. It will greatly improve the content at readthedocs. Additionally: * Add a 'doc' env to tox.ini * Changed default highlight language for sphinx conf from python to yaml most examples in documentation are yaml configs * Updated datasource examples to highlight sh code properly --- tox.ini | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tox.ini') diff --git a/tox.ini b/tox.ini index e7a6f22c..9424ae51 100644 --- a/tox.ini +++ b/tox.ini @@ -28,3 +28,9 @@ setenv = [flake8] ignore=H404,H405,H105,H301,H104,H403,H101 exclude = .venv,.tox,dist,doc,*egg,.git,build,tools + +[testenv:doc] +basepython = python3 +deps = {[testenv]deps} + sphinx +commands = {envpython} -m sphinx {posargs:doc/rtd doc/rtd_html} -- cgit v1.2.3 From 760a4f1852ee7241c00804ebf210b6a4b1e9063d Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Tue, 4 Oct 2016 09:56:10 -0500 Subject: unittests: fix use of mock 2.0 'assert_called' when running make check Some of the new DigitalOcean unittests were written to use 'assert_called', which is only available in mock versions 2.0. Because of this, the failure would only occur in releases less than yakkety and not in 'tox'. Add a 'xenial' entry to tox.ini with versions from xenial. --- .../unittests/test_datasource/test_digitalocean.py | 6 ++--- tox.ini | 27 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'tox.ini') diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py index bdfe0ba2..7bde0820 100644 --- a/tests/unittests/test_datasource/test_digitalocean.py +++ b/tests/unittests/test_datasource/test_digitalocean.py @@ -162,7 +162,7 @@ class TestDataSourceDigitalOcean(TestCase): m_read_sysinfo.return_value = (False, None) ds = self.get_ds(get_sysinfo=None) self.assertEqual(False, ds.get_data()) - m_read_sysinfo.assert_called() + self.assertTrue(m_read_sysinfo.called) @mock.patch('cloudinit.sources.helpers.digitalocean.read_metadata') def test_metadata(self, mock_readmd): @@ -172,7 +172,7 @@ class TestDataSourceDigitalOcean(TestCase): ret = ds.get_data() self.assertTrue(ret) - mock_readmd.assert_called() + self.assertTrue(mock_readmd.called) self.assertEqual(DO_META.get('user_data'), ds.get_userdata_raw()) self.assertEqual(DO_META.get('vendor_data'), ds.get_vendordata_raw()) @@ -196,7 +196,7 @@ class TestDataSourceDigitalOcean(TestCase): ret = ds.get_data() self.assertTrue(ret) - mock_readmd.assert_called() + self.assertTrue(mock_readmd.called) # Multiple keys self.assertEqual(metadata['public_keys'], ds.get_public_ssh_keys()) diff --git a/tox.ini b/tox.ini index 9424ae51..729de2a6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py3,flake8 +envlist = py27, py3, flake8, xenial recreate = True [testenv] @@ -34,3 +34,28 @@ basepython = python3 deps = {[testenv]deps} sphinx commands = {envpython} -m sphinx {posargs:doc/rtd doc/rtd_html} + +[testenv:xenial] +basepython = python3 +deps = + # requirements + jinja2==2.8 + pyyaml==3.11 + PrettyTable==0.7.2 + oauthlib==1.0.3 + pyserial==3.0.1 + configobj==5.0.6 + requests==2.9.1 + # jsonpatch ubuntu is 1.10, not 1.19 (#839779) + jsonpatch==1.10 + six==1.10.0 + # test-requirements + httpretty==0.8.6 + mock==1.3.0 + nose==1.3.7 + unittest2==1.1.0 + contextlib2==0.5.1 + pep8==1.7.0 + pyflakes==1.1.0 + flake8==2.5.4 + hacking==0.10.2 -- cgit v1.2.3 From e8730078df8c99696b1b684e09c803eef7c4926c Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 30 Sep 2016 15:53:42 -0400 Subject: Fix python2.6 things found running in centos 6. This gets the tests running in centos 6. * ProcessExecutionError: remove setting of .message Nothing in cloud-init seems to use .message anywhere, so it does not seem necessary. The reason to change it is that on 2.6 it spits out: cloudinit/util.py:286: DeprecationWarning: BaseException.message * tox.ini: add a centos6 environment the tox versions listed here replicate a centos6 install with packages from EPEL. You will still need a python2.6 to run this env so we do not enable it by default. --- cloudinit/sources/DataSourceAltCloud.py | 6 ++---- cloudinit/sources/helpers/azure.py | 2 +- cloudinit/util.py | 7 ++----- tests/unittests/test_handler/test_handler_apt_conf_v1.py | 2 +- tests/unittests/test_util.py | 2 +- tox.ini | 16 ++++++++++++++++ 6 files changed, 23 insertions(+), 12 deletions(-) (limited to 'tox.ini') diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py index 48136f7c..20345389 100644 --- a/cloudinit/sources/DataSourceAltCloud.py +++ b/cloudinit/sources/DataSourceAltCloud.py @@ -195,8 +195,7 @@ class DataSourceAltCloud(sources.DataSource): (cmd_out, _err) = util.subp(cmd) LOG.debug(('Command: %s\nOutput%s') % (' '.join(cmd), cmd_out)) except ProcessExecutionError as _err: - util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), - _err.message) + util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err) return False except OSError as _err: util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err) @@ -211,8 +210,7 @@ class DataSourceAltCloud(sources.DataSource): (cmd_out, _err) = util.subp(cmd) LOG.debug(('Command: %s\nOutput%s') % (' '.join(cmd), cmd_out)) except ProcessExecutionError as _err: - util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), - _err.message) + util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err) return False except OSError as _err: util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py index 689ed4cc..1b3e9b70 100644 --- a/cloudinit/sources/helpers/azure.py +++ b/cloudinit/sources/helpers/azure.py @@ -232,7 +232,7 @@ class WALinuxAgentShim(object): def _get_value_from_leases_file(fallback_lease_file): leases = [] content = util.load_file(fallback_lease_file) - LOG.debug("content is {}".format(content)) + LOG.debug("content is %s", content) for line in content.splitlines(): if 'unknown-245' in line: # Example line from Ubuntu diff --git a/cloudinit/util.py b/cloudinit/util.py index eb3e5899..4cff83c5 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -199,7 +199,7 @@ def fully_decoded_payload(part): encoding = charset.input_codec else: encoding = 'utf-8' - return cte_payload.decode(encoding, errors='surrogateescape') + return cte_payload.decode(encoding, 'surrogateescape') return cte_payload @@ -282,9 +282,6 @@ class ProcessExecutionError(IOError): 'reason': self.reason, } IOError.__init__(self, message) - # For backward compatibility with Python 2. - if not hasattr(self, 'message'): - self.message = message class SeLinuxGuard(object): @@ -1821,7 +1818,7 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False, def ldecode(data, m='utf-8'): if not isinstance(data, bytes): return data - return data.decode(m, errors=decode) + return data.decode(m, decode) out = ldecode(out) err = ldecode(err) diff --git a/tests/unittests/test_handler/test_handler_apt_conf_v1.py b/tests/unittests/test_handler/test_handler_apt_conf_v1.py index 45714efd..64acc3e0 100644 --- a/tests/unittests/test_handler/test_handler_apt_conf_v1.py +++ b/tests/unittests/test_handler/test_handler_apt_conf_v1.py @@ -118,7 +118,7 @@ class TestConversion(TestCase): def test_convert_with_apt_mirror(self): mirror = 'http://my.mirror/ubuntu' f = cc_apt_configure.convert_to_v3_apt_format({'apt_mirror': mirror}) - self.assertIn(mirror, {m['uri'] for m in f['apt']['primary']}) + self.assertIn(mirror, set(m['uri'] for m in f['apt']['primary'])) def test_no_old_content(self): mirror = 'http://my.mirror/ubuntu' diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index fc6b9d40..881509aa 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -553,7 +553,7 @@ class TestSubp(helpers.TestCase): def test_subp_decode_invalid_utf8_replaces(self): (out, _err) = util.subp(self.stdin2out, capture=True, data=self.utf8_invalid) - expected = self.utf8_invalid.decode('utf-8', errors='replace') + expected = self.utf8_invalid.decode('utf-8', 'replace') self.assertEqual(out, expected) def test_subp_decode_strict_raises(self): diff --git a/tox.ini b/tox.ini index 729de2a6..277858ed 100644 --- a/tox.ini +++ b/tox.ini @@ -59,3 +59,19 @@ deps = pyflakes==1.1.0 flake8==2.5.4 hacking==0.10.2 + +[testenv:centos6] +basepython = python2.6 +commands = nosetests {posargs:tests} +deps = + # requirements + argparse==1.2.1 + jinja2==2.2.1 + pyyaml==3.10 + PrettyTable==0.7.2 + oauthlib==0.6.0 + configobj==4.6.0 + requests==2.6.0 + jsonpatch==1.2 + six==1.9.0 + -r{toxinidir}/test-requirements.txt -- cgit v1.2.3 From c12f4dd835077e3aa39e9056c25f136ff6a6655b Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Thu, 20 Oct 2016 15:49:59 -0600 Subject: Add coverage collection to tox unit tests. First step in increasing coverage is knowing what coverage is currently at. By default, tox only runs coverage on py3 as it is slower to run with coverage. --- .gitignore | 1 + test-requirements.txt | 1 + tox.ini | 3 +++ 3 files changed, 5 insertions(+) (limited to 'tox.ini') diff --git a/.gitignore b/.gitignore index 77eb9c74..865cac15 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist *.pyc __pycache__ .tox +.coverage diff --git a/test-requirements.txt b/test-requirements.txt index 6bf38940..0e7fc8fb 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,6 +3,7 @@ httpretty>=0.7.1 mock nose unittest2 +coverage # Only needed if you want to know the test times # nose-timer diff --git a/tox.ini b/tox.ini index 277858ed..08318a9f 100644 --- a/tox.ini +++ b/tox.ini @@ -19,6 +19,9 @@ setenv = [testenv:py3] basepython = python3 +commands = {envpython} -m nose \ + {posargs:--with-coverage --cover-erase \ + --cover-branches --cover-package=cloudinit --cover-inclusive} [testenv:py26] commands = nosetests {posargs:tests} -- cgit v1.2.3