Fix Python code style for inventory_builder (#5362)
This commit is contained in:
parent
f7aea8ed89
commit
401d441c10
4 changed files with 18 additions and 13 deletions
|
@ -42,10 +42,14 @@ syntax-check:
|
||||||
tox-inventory-builder:
|
tox-inventory-builder:
|
||||||
stage: unit-tests
|
stage: unit-tests
|
||||||
extends: .job
|
extends: .job
|
||||||
|
before_script:
|
||||||
|
- ./tests/scripts/rebase.sh
|
||||||
|
- apt-get update && apt-get install -y python3-pip
|
||||||
|
- update-alternatives --install /usr/bin/python python /usr/bin/python3 10
|
||||||
|
- python -m pip install -r tests/requirements.txt
|
||||||
script:
|
script:
|
||||||
- pip install tox
|
- pip3 install tox
|
||||||
- cd contrib/inventory_builder && tox
|
- cd contrib/inventory_builder && tox
|
||||||
when: manual
|
|
||||||
except: ['triggers', 'master']
|
except: ['triggers', 'master']
|
||||||
|
|
||||||
markdownlint:
|
markdownlint:
|
||||||
|
|
|
@ -224,8 +224,8 @@ class KubesprayInventory(object):
|
||||||
end = int(ip_address(end_address))
|
end = int(ip_address(end_address))
|
||||||
except Exception:
|
except Exception:
|
||||||
# Python 2.7
|
# Python 2.7
|
||||||
start = int(ip_address(unicode(start_address)))
|
start = int(ip_address(str(start_address)))
|
||||||
end = int(ip_address(unicode(end_address)))
|
end = int(ip_address(str(end_address)))
|
||||||
return [ip_address(ip).exploded for ip in range(start, end + 1)]
|
return [ip_address(ip).exploded for ip in range(start, end + 1)]
|
||||||
|
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import inventory
|
||||||
import mock
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
@ -43,8 +44,8 @@ class TestInventory(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_ip_from_opts_invalid(self):
|
def test_get_ip_from_opts_invalid(self):
|
||||||
optstring = "notanaddr=value something random!chars:D"
|
optstring = "notanaddr=value something random!chars:D"
|
||||||
self.assertRaisesRegexp(ValueError, "IP parameter not found",
|
self.assertRaisesRegex(ValueError, "IP parameter not found",
|
||||||
self.inv.get_ip_from_opts, optstring)
|
self.inv.get_ip_from_opts, optstring)
|
||||||
|
|
||||||
def test_ensure_required_groups(self):
|
def test_ensure_required_groups(self):
|
||||||
groups = ['group1', 'group2']
|
groups = ['group1', 'group2']
|
||||||
|
@ -63,8 +64,8 @@ class TestInventory(unittest.TestCase):
|
||||||
def test_get_host_id_invalid(self):
|
def test_get_host_id_invalid(self):
|
||||||
bad_hostnames = ['node', 'no99de', '01node', 'node.111111']
|
bad_hostnames = ['node', 'no99de', '01node', 'node.111111']
|
||||||
for hostname in bad_hostnames:
|
for hostname in bad_hostnames:
|
||||||
self.assertRaisesRegexp(ValueError, "Host name must end in an",
|
self.assertRaisesRegex(ValueError, "Host name must end in an",
|
||||||
self.inv.get_host_id, hostname)
|
self.inv.get_host_id, hostname)
|
||||||
|
|
||||||
def test_build_hostnames_add_one(self):
|
def test_build_hostnames_add_one(self):
|
||||||
changed_hosts = ['10.90.0.2']
|
changed_hosts = ['10.90.0.2']
|
||||||
|
@ -192,8 +193,8 @@ class TestInventory(unittest.TestCase):
|
||||||
('node2', {'ansible_host': '10.90.0.3',
|
('node2', {'ansible_host': '10.90.0.3',
|
||||||
'ip': '10.90.0.3',
|
'ip': '10.90.0.3',
|
||||||
'access_ip': '10.90.0.3'})])
|
'access_ip': '10.90.0.3'})])
|
||||||
self.assertRaisesRegexp(ValueError, "Unable to find host",
|
self.assertRaisesRegex(ValueError, "Unable to find host",
|
||||||
self.inv.delete_host_by_ip, existing_hosts, ip)
|
self.inv.delete_host_by_ip, existing_hosts, ip)
|
||||||
|
|
||||||
def test_purge_invalid_hosts(self):
|
def test_purge_invalid_hosts(self):
|
||||||
proper_hostnames = ['node1', 'node2']
|
proper_hostnames = ['node1', 'node2']
|
||||||
|
@ -309,8 +310,8 @@ class TestInventory(unittest.TestCase):
|
||||||
|
|
||||||
def test_range2ips_incorrect_range(self):
|
def test_range2ips_incorrect_range(self):
|
||||||
host_range = ['10.90.0.4-a.9b.c.e']
|
host_range = ['10.90.0.4-a.9b.c.e']
|
||||||
self.assertRaisesRegexp(Exception, "Range of ip_addresses isn't valid",
|
self.assertRaisesRegex(Exception, "Range of ip_addresses isn't valid",
|
||||||
self.inv.range2ips, host_range)
|
self.inv.range2ips, host_range)
|
||||||
|
|
||||||
def test_build_hostnames_different_ips_add_one(self):
|
def test_build_hostnames_different_ips_add_one(self):
|
||||||
changed_hosts = ['10.90.0.2,192.168.0.2']
|
changed_hosts = ['10.90.0.2,192.168.0.2']
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[tox]
|
[tox]
|
||||||
minversion = 1.6
|
minversion = 1.6
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
envlist = pep8, py27
|
envlist = pep8, py33
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
whitelist_externals = py.test
|
whitelist_externals = py.test
|
||||||
|
|
Loading…
Reference in a new issue