summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2016-05-19 15:33:15 -0700
committerJoshua Harlow <harlowja@gmail.com>2016-05-19 15:33:15 -0700
commit2fb5af62229b8975910bf0ef63731047bd8d7e63 (patch)
treedc1d367224916780a319f2d15757b7cf221884e3
parent6b97c4e462b19374d6af807b1f5b9c087aa97996 (diff)
downloadvyos-cloud-init-2fb5af62229b8975910bf0ef63731047bd8d7e63.tar.gz
vyos-cloud-init-2fb5af62229b8975910bf0ef63731047bd8d7e63.zip
Fix up tests and flake8 warnings
-rw-r--r--cloudinit/net/__init__.py2
-rw-r--r--cloudinit/net/eni.py16
-rw-r--r--cloudinit/sources/DataSourceConfigDrive.py1
-rw-r--r--cloudinit/stages.py2
-rw-r--r--tests/unittests/helpers.py1
-rw-r--r--tests/unittests/test__init__.py1
-rw-r--r--tests/unittests/test_datasource/test_cloudsigma.py1
-rw-r--r--tests/unittests/test_datasource/test_configdrive.py41
-rw-r--r--tests/unittests/test_datasource/test_nocloud.py2
-rw-r--r--tests/unittests/test_datasource/test_smartos.py2
-rw-r--r--tests/unittests/test_net.py6
-rw-r--r--tests/unittests/test_rh_subscription.py5
-rw-r--r--tox.ini4
13 files changed, 41 insertions, 43 deletions
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index ad44911b..ba0e39ae 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -49,8 +49,8 @@ DEFAULT_PRIMARY_INTERFACE = 'eth0'
# whole module can be easily extracted and placed into other
# code-bases (curtin for example).
+
def write_file(path, content):
- """Simple writing a file helper."""
base_path = os.path.dirname(path)
if not os.path.isdir(base_path):
os.makedirs(base_path)
diff --git a/cloudinit/net/eni.py b/cloudinit/net/eni.py
index adb31c22..18bae97a 100644
--- a/cloudinit/net/eni.py
+++ b/cloudinit/net/eni.py
@@ -258,7 +258,7 @@ class Renderer(object):
return content
def _render_route(self, route, indent=""):
- """ When rendering routes for an iface, in some cases applying a route
+ """When rendering routes for an iface, in some cases applying a route
may result in the route command returning non-zero which produces
some confusing output for users manually using ifup/ifdown[1]. To
that end, we will optionally include an '|| true' postfix to each
@@ -302,7 +302,7 @@ class Renderer(object):
return content
def _render_interfaces(self, network_state):
- ''' Given state, emit etc/network/interfaces content '''
+ '''Given state, emit etc/network/interfaces content'''
content = ""
interfaces = network_state.get('interfaces')
@@ -336,8 +336,8 @@ class Renderer(object):
iface['control'] = subnet.get('control', 'auto')
if iface['mode'].endswith('6'):
iface['inet'] += '6'
- elif iface['mode'] == 'static' \
- and ":" in subnet['address']:
+ elif (iface['mode'] == 'static'
+ and ":" in subnet['address']):
iface['inet'] += '6'
if iface['mode'].startswith('dhcp'):
iface['mode'] = 'dhcp'
@@ -359,10 +359,10 @@ class Renderer(object):
content = content.replace('mac_address', 'hwaddress')
return content
- def render_network_state(self,
- target, network_state, eni="etc/network/interfaces",
- links_prefix=LINKS_FNAME_PREFIX,
- netrules='etc/udev/rules.d/70-persistent-net.rules'):
+ def render_network_state(
+ self, target, network_state,
+ eni="etc/network/interfaces", links_prefix=LINKS_FNAME_PREFIX,
+ netrules='etc/udev/rules.d/70-persistent-net.rules'):
fpeni = os.path.join(target, eni)
net.write_file(fpeni, self._render_interfaces(network_state))
diff --git a/cloudinit/sources/DataSourceConfigDrive.py b/cloudinit/sources/DataSourceConfigDrive.py
index 70373b43..4478c4e2 100644
--- a/cloudinit/sources/DataSourceConfigDrive.py
+++ b/cloudinit/sources/DataSourceConfigDrive.py
@@ -18,7 +18,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import copy
import os
from cloudinit import log as logging
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 5dd31539..b837009a 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -44,8 +44,8 @@ from cloudinit import helpers
from cloudinit import importer
from cloudinit import log as logging
from cloudinit import net
-from cloudinit.reporting import events
from cloudinit.net import cmdline
+from cloudinit.reporting import events
from cloudinit import sources
from cloudinit import type_utils
from cloudinit import util
diff --git a/tests/unittests/helpers.py b/tests/unittests/helpers.py
index 7b4d44e8..8d46a8bf 100644
--- a/tests/unittests/helpers.py
+++ b/tests/unittests/helpers.py
@@ -45,6 +45,7 @@ else:
if _PY_MINOR == 4 and _PY_MICRO < 3:
FIX_HTTPRETTY = True
+
# Makes the old path start
# with new base instead of whatever
# it previously had
diff --git a/tests/unittests/test__init__.py b/tests/unittests/test__init__.py
index a9b35afe..0154784a 100644
--- a/tests/unittests/test__init__.py
+++ b/tests/unittests/test__init__.py
@@ -1,7 +1,6 @@
import os
import shutil
import tempfile
-import unittest2
from cloudinit import handlers
from cloudinit import helpers
diff --git a/tests/unittests/test_datasource/test_cloudsigma.py b/tests/unittests/test_datasource/test_cloudsigma.py
index 7950fc52..2a42ce0c 100644
--- a/tests/unittests/test_datasource/test_cloudsigma.py
+++ b/tests/unittests/test_datasource/test_cloudsigma.py
@@ -6,7 +6,6 @@ from cloudinit.cs_utils import Cepko
from cloudinit.sources import DataSourceCloudSigma
from .. import helpers as test_helpers
-from ..helpers import SkipTest
SERVER_CONTEXT = {
"cpu": 1000,
diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py
index 1db50798..5395e544 100644
--- a/tests/unittests/test_datasource/test_configdrive.py
+++ b/tests/unittests/test_datasource/test_configdrive.py
@@ -368,30 +368,32 @@ class TestNetJson(TestCase):
self.assertEqual(myds.network_config, network_config)
def test_network_config_conversions(self):
- """Tests a bunch of input network json and checks the expected conversions."""
+ """Tests a bunch of input network json and checks the
+ expected conversions."""
in_datas = [
NETWORK_DATA,
{
'services': [{'type': 'dns', 'address': '172.19.0.12'}],
- 'networks': [
- {'network_id': 'dacd568d-5be6-4786-91fe-750c374b78b4',
- 'type': 'ipv4', 'netmask': '255.255.252.0',
- 'link': 'tap1a81968a-79',
- 'routes': [
- {
- 'netmask': '0.0.0.0',
- 'network': '0.0.0.0',
- 'gateway': '172.19.3.254'
- },
- ],
- 'ip_address': '172.19.1.34',
- 'id': 'network0',
+ 'networks': [{
+ 'network_id': 'dacd568d-5be6-4786-91fe-750c374b78b4',
+ 'type': 'ipv4',
+ 'netmask': '255.255.252.0',
+ 'link': 'tap1a81968a-79',
+ 'routes': [{
+ 'netmask': '0.0.0.0',
+ 'network': '0.0.0.0',
+ 'gateway': '172.19.3.254',
+ }],
+ 'ip_address': '172.19.1.34',
+ 'id': 'network0',
+ }],
+ 'links': [{
+ 'type': 'bridge',
+ 'vif_id': '1a81968a-797a-400f-8a80-567f997eb93f',
+ 'ethernet_mac_address': 'fa:16:3e:ed:9a:59',
+ 'id': 'tap1a81968a-79',
+ 'mtu': None,
}],
- 'links': [
- {'type': 'bridge',
- 'vif_id': '1a81968a-797a-400f-8a80-567f997eb93f',
- 'ethernet_mac_address': 'fa:16:3e:ed:9a:59',
- 'id': 'tap1a81968a-79', 'mtu': None}]
},
]
out_datas = [
@@ -440,6 +442,7 @@ class TestNetJson(TestCase):
'address': '172.19.1.34',
'netmask': '255.255.252.0',
'type': 'static',
+ 'ipv4': True,
'routes': [{
'gateway': '172.19.3.254',
'netmask': '0.0.0.0',
diff --git a/tests/unittests/test_datasource/test_nocloud.py b/tests/unittests/test_datasource/test_nocloud.py
index 077603b4..b0fa1130 100644
--- a/tests/unittests/test_datasource/test_nocloud.py
+++ b/tests/unittests/test_datasource/test_nocloud.py
@@ -7,6 +7,8 @@ import os
import shutil
import tempfile
+import yaml
+
class TestNoCloudDataSource(TestCase):
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index 2f159ac4..28f56039 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -42,7 +42,7 @@ from cloudinit import helpers as c_helpers
from cloudinit.util import b64e
from .. import helpers
-from ..helpers import mock, SkipTest
+from ..helpers import mock
MOCK_RETURNS = {
'hostname': 'test-host',
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index faf0f0fb..7998111a 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -1,13 +1,11 @@
from cloudinit import net
-from cloudinit import util
-
-from cloudinit import net
from cloudinit.net import cmdline
from cloudinit.net import eni
from cloudinit.net import network_state
+from cloudinit import util
-from .helpers import TestCase
from .helpers import mock
+from .helpers import TestCase
import base64
import copy
diff --git a/tests/unittests/test_rh_subscription.py b/tests/unittests/test_rh_subscription.py
index e4dcc58b..891dbe77 100644
--- a/tests/unittests/test_rh_subscription.py
+++ b/tests/unittests/test_rh_subscription.py
@@ -10,13 +10,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
import logging
-import mock
-import unittest
-
from cloudinit.config import cc_rh_subscription
+from cloudinit import util
from .helpers import TestCase, mock
diff --git a/tox.ini b/tox.ini
index b92ebac1..7802a291 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,11 +1,11 @@
[tox]
-envlist = py27,py3,flake8
+envlist = py26,py27,py3,flake8
recreate = True
usedevelop = True
[testenv]
-commands = python -m nose {posargs:tests}
+commands = nosetests {posargs:tests}
deps = -r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
setenv =