aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryayogev <yaronyogev@gmail.com>2017-08-21 10:06:31 +0300
committeryayogev <yaronyogev@gmail.com>2017-08-21 10:06:31 +0300
commit5123fe510da52369a73dfbfc64f2f25d05ff90af (patch)
treedb31874dc11da0dc9accf3a99876b5050b2dd796
parentf1a8bef9f98a4601de16ee96ac1e68b212d104d8 (diff)
fix CLI unit tests
Change-Id: Ie54f56adf2cd4cc42cf89c2b30004c1cf15eb2d6 Signed-off-by: yayogev <yaronyogev@gmail.com>
-rw-r--r--app/discover/fetchers/cli/cli_access.py1
-rw-r--r--app/discover/fetchers/cli/cli_fetch_host_pnics.py18
-rw-r--r--app/discover/fetchers/cli/cli_fetch_vservice_vnics.py4
-rw-r--r--app/test/fetch/cli_fetch/test_cli_fetch_host_pnics.py2
-rw-r--r--app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_ovs.py10
-rw-r--r--app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_vpp.py5
-rw-r--r--app/test/fetch/cli_fetch/test_cli_fetch_vconnectors.py66
-rw-r--r--app/test/fetch/cli_fetch/test_data/cli_fetch_vservice_vnics.py4
8 files changed, 27 insertions, 83 deletions
diff --git a/app/discover/fetchers/cli/cli_access.py b/app/discover/fetchers/cli/cli_access.py
index 1db84ea..11579bd 100644
--- a/app/discover/fetchers/cli/cli_access.py
+++ b/app/discover/fetchers/cli/cli_access.py
@@ -204,3 +204,4 @@ class CliAccess(BinaryConverter, Fetcher):
matches = regex.search(line)
if matches:
o[name] = matches.group(1)
+ break
diff --git a/app/discover/fetchers/cli/cli_fetch_host_pnics.py b/app/discover/fetchers/cli/cli_fetch_host_pnics.py
index 3516e25..5df4d3b 100644
--- a/app/discover/fetchers/cli/cli_fetch_host_pnics.py
+++ b/app/discover/fetchers/cli/cli_fetch_host_pnics.py
@@ -19,12 +19,18 @@ class CliFetchHostPnics(CliAccess):
self.inv = InventoryMgr()
self.ethtool_attr = re.compile('^\s+([^:]+):\s(.*)$')
self.regexps = [
- {'name': 'mac_address', 're': '^.*\sHWaddr\s(\S+)(\s.*)?$'},
- {'name': 'mac_address', 're': '^.*\sether\s(\S+)(\s.*)?$'},
- {'name': 'IP Address', 're': '^\s*inet addr:?(\S+)\s.*$'},
- {'name': 'IP Address', 're': '^\s*inet ([0-9.]+)\s.*$'},
- {'name': 'IPv6 Address', 're': '^\s*inet6 addr:\s*(\S+)(\s.*)?$'},
- {'name': 'IPv6 Address', 're': '^\s*inet6 \s*(\S+)(\s.*)?$'}
+ {'name': 'mac_address', 're': '^.*\sHWaddr\s(\S+)(\s.*)?$',
+ 'description': 'MAC address with HWaddr'},
+ {'name': 'mac_address', 're': '^.*\sether\s(\S+)(\s.*)?$',
+ 'description': 'MAC address with ether'},
+ {'name': 'IP Address', 're': '^\s*inet addr:?(\S+)\s.*$',
+ 'description': 'IP Address with "inet addr"'},
+ {'name': 'IP Address', 're': '^\s*inet ([0-9.]+)\s.*$',
+ 'description': 'IP Address with "inet"'},
+ {'name': 'IPv6 Address', 're': '^\s*inet6 addr:\s*(\S+)(\s.*)?$',
+ 'description': 'IPv6 Address with "inet6 addr"'},
+ {'name': 'IPv6 Address', 're': '^\s*inet6 \s*(\S+)(\s.*)?$',
+ 'description': 'IPv6 Address with "inet6"'}
]
def get(self, id):
diff --git a/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py b/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py
index 44ac8d6..d10d99e 100644
--- a/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py
+++ b/app/discover/fetchers/cli/cli_fetch_vservice_vnics.py
@@ -21,10 +21,10 @@ class CliFetchVserviceVnics(CliAccess):
self.regexps = [
{'name': 'mac_address', 're': '^.*\sHWaddr\s(\S+)(\s.*)?$'},
{'name': 'mac_address', 're': '^.*\sether\s(\S+)(\s.*)?$'},
- {'name': 'netmask', 're': '^.*\sMask:\s?([0-9.]+)(\s.*)?$'},
- {'name': 'netmask', 're': '^.*\snetmask\s([0-9.]+)(\s.*)?$'},
{'name': 'IP Address', 're': '^\s*inet addr:(\S+)\s.*$'},
{'name': 'IP Address', 're': '^\s*inet ([0-9.]+)\s.*$'},
+ {'name': 'netmask', 're': '^.*\sMask:\s?([0-9.]+)(\s.*)?$'},
+ {'name': 'netmask', 're': '^.*\snetmask\s([0-9.]+)(\s.*)?$'},
{'name': 'IPv6 Address',
're': '^\s*inet6 addr: ?\s*([0-9a-f:/]+)(\s.*)?$'},
{'name': 'IPv6 Address',
diff --git a/app/test/fetch/cli_fetch/test_cli_fetch_host_pnics.py b/app/test/fetch/cli_fetch/test_cli_fetch_host_pnics.py
index f5f327e..26885f3 100644
--- a/app/test/fetch/cli_fetch/test_cli_fetch_host_pnics.py
+++ b/app/test/fetch/cli_fetch/test_cli_fetch_host_pnics.py
@@ -118,7 +118,7 @@ class TestCliFetchHostPnics(TestFetch):
def test_handle_ipv6_address_line(self):
self.fetcher.handle_line(RAW_INTERFACE, IPV6_ADDRESS_LINE)
self.assertEqual(RAW_INTERFACE['IPv6 Address'], IPV6_ADDRESS,
- "Can' get the correct ipv6 address")
+ "Can't get the correct ipv6 address")
def test_handle_ipv4_address_line(self):
self.fetcher.handle_line(RAW_INTERFACE, IPV4_ADDRESS_LINE)
diff --git a/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_ovs.py b/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_ovs.py
index 24a1b5d..348d1b8 100644
--- a/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_ovs.py
+++ b/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_ovs.py
@@ -7,7 +7,8 @@
# which accompanies this distribution, and is available at #
# http://www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
-from discover.cli_fetch_instance_vnics_ovs import CliFetchInstanceVnicsOvs
+from discover.fetchers.cli.cli_fetch_instance_vnics \
+ import CliFetchInstanceVnics
from test.fetch.test_fetch import TestFetch
from test.fetch.cli_fetch.test_data.cli_fetch_instance_vnics import *
from unittest.mock import MagicMock
@@ -17,7 +18,7 @@ class TestCliFetchInstanceVnicsOvs(TestFetch):
def setUp(self):
self.configure_environment()
- self.fetcher = CliFetchInstanceVnicsOvs()
+ self.fetcher = CliFetchInstanceVnics()
self.fetcher.set_env(self.env)
def test_set_vnic_properties(self):
@@ -29,8 +30,9 @@ class TestCliFetchInstanceVnicsOvs(TestFetch):
# reset method
self.fetcher.inv.set = original_set
- self.assertIn("source_bridge", VNIC, "Can't set source_bridge for ovs vnic")
+ self.assertIn("source_bridge", VNIC,
+ "Can't set source_bridge for ovs vnic")
def test_get_vnic_name(self):
name = self.fetcher.get_vnic_name(VNIC, INSATNCE)
- self.assertNotEqual(name, None, "Can't get vnic name") \ No newline at end of file
+ self.assertNotEqual(name, None, "Can't get vnic name")
diff --git a/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_vpp.py b/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_vpp.py
index 46c25fb..a54b881 100644
--- a/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_vpp.py
+++ b/app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_vpp.py
@@ -7,7 +7,8 @@
# which accompanies this distribution, and is available at #
# http://www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
-from discover.cli_fetch_instance_vnics_vpp import CliFetchInstanceVnicsVpp
+from discover.fetchers.cli.cli_fetch_instance_vnics_vpp \
+ import CliFetchInstanceVnicsVpp
from test.fetch.cli_fetch.test_data.cli_fetch_instance_vnics import *
from test.fetch.test_fetch import TestFetch
@@ -20,4 +21,4 @@ class TestCliFetchInstanceVnicsVpp(TestFetch):
def test_get_name(self):
name = self.fetcher.get_vnic_name(VNIC, INSATNCE)
- self.assertNotEqual(name, None, "Can't get vnic name") \ No newline at end of file
+ self.assertNotEqual(name, None, "Can't get vnic name")
diff --git a/app/test/fetch/cli_fetch/test_cli_fetch_vconnectors.py b/app/test/fetch/cli_fetch/test_cli_fetch_vconnectors.py
deleted file mode 100644
index 23e0a99..0000000
--- a/app/test/fetch/cli_fetch/test_cli_fetch_vconnectors.py
+++ /dev/null
@@ -1,66 +0,0 @@
-###############################################################################
-# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
-# and others #
-# #
-# All rights reserved. This program and the accompanying materials #
-# are made available under the terms of the Apache License, Version 2.0 #
-# which accompanies this distribution, and is available at #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-###############################################################################
-from discover.fetchers.cli.cli_fetch_vconnectors import CliFetchVconnectors
-from test.fetch.test_fetch import TestFetch
-from test.fetch.cli_fetch.test_data.cli_fetch_vconnectors import *
-from unittest.mock import MagicMock
-
-
-class TestCliFetchVconnectors(TestFetch):
-
- def setUp(self):
- self.configure_environment()
- self.fetcher = CliFetchVconnectors()
- self.fetcher.set_env(self.env)
-
- def test_get(self):
- # store original methods
- original_get_by_id = self.fetcher.inv.get_by_id
- original_get_vconnectors = self.fetcher.get_vconnectors
-
- # mock methods
- self.fetcher.inv.get_by_id = MagicMock(return_value=HOST)
- self.fetcher.get_vconnectors = MagicMock(return_value=VCONNECTORS)
-
- result = self.fetcher.get(VCONNECTORS_FOLDER['id'])
-
- # reset methods
- self.fetcher.inv.get_by_id = original_get_by_id
- self.fetcher.get_vconnectors = original_get_vconnectors
-
- self.assertEqual(result, VCONNECTORS, "Can't get the vconnectors")
-
- def test_get_without_host(self):
- # store original methods
- original_get_by_id = self.fetcher.inv.get_by_id
-
- # mock methods
- self.fetcher.inv.get_by_id = MagicMock(return_value=[])
-
- result = self.fetcher.get(VCONNECTORS_FOLDER['id'])
-
- # reset methods
- self.fetcher.inv.get_by_id = original_get_by_id
-
- self.assertEqual(result, [], "Can't get empty array when the host doesn't exist")
-
- def test_get_with_wrong_host(self):
- # store original methods
- original_get_by_id = self.fetcher.inv.get_by_id
-
- # mock methods
- self.fetcher.inv.get_by_id = MagicMock(return_value=WRONG_HOST)
-
- result = self.fetcher.get(VCONNECTORS_FOLDER['id'])
-
- # reset methods
- self.fetcher.inv.get_by_id = original_get_by_id
-
- self.assertEqual(result, [], "Can't get empty array when the host doesn't contain host type") \ No newline at end of file
diff --git a/app/test/fetch/cli_fetch/test_data/cli_fetch_vservice_vnics.py b/app/test/fetch/cli_fetch/test_data/cli_fetch_vservice_vnics.py
index 0b60af5..bef0ed2 100644
--- a/app/test/fetch/cli_fetch/test_data/cli_fetch_vservice_vnics.py
+++ b/app/test/fetch/cli_fetch/test_data/cli_fetch_vservice_vnics.py
@@ -198,7 +198,7 @@ RAW_VNIC = {
"vnic_type": "vservice_vnic"
}
-NETWORK = [{
+NETWORK = {
"admin_state_up": True,
"cidrs": [
"172.16.13.0/24"
@@ -252,7 +252,7 @@ NETWORK = [{
},
"tenant_id": "75c0eb79ff4a42b0ae4973c8375ddf40",
"type": "network"
-}]
+}
VSERVICE = {
"children_url": "/osdna_dev/discover.py?type=tree&id=qdhcp-8673c48a-f137-4497-b25d-08b7b218fd17",