fix CLI unit tests 23/39723/1
authoryayogev <yaronyogev@gmail.com>
Mon, 21 Aug 2017 07:06:31 +0000 (10:06 +0300)
committeryayogev <yaronyogev@gmail.com>
Mon, 21 Aug 2017 07:06:31 +0000 (10:06 +0300)
Change-Id: Ie54f56adf2cd4cc42cf89c2b30004c1cf15eb2d6
Signed-off-by: yayogev <yaronyogev@gmail.com>
app/discover/fetchers/cli/cli_access.py
app/discover/fetchers/cli/cli_fetch_host_pnics.py
app/discover/fetchers/cli/cli_fetch_vservice_vnics.py
app/test/fetch/cli_fetch/test_cli_fetch_host_pnics.py
app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_ovs.py
app/test/fetch/cli_fetch/test_cli_fetch_instance_vnics_vpp.py
app/test/fetch/cli_fetch/test_cli_fetch_vconnectors.py [deleted file]
app/test/fetch/cli_fetch/test_data/cli_fetch_vservice_vnics.py

index 1db84ea..11579bd 100644 (file)
@@ -204,3 +204,4 @@ class CliAccess(BinaryConverter, Fetcher):
             matches = regex.search(line)
             if matches:
                 o[name] = matches.group(1)
+                break
index 3516e25..5df4d3b 100644 (file)
@@ -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):
index 44ac8d6..d10d99e 100644 (file)
@@ -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',
index f5f327e..26885f3 100644 (file)
@@ -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)
index 24a1b5d..348d1b8 100644 (file)
@@ -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")
index 46c25fb..a54b881 100644 (file)
@@ -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 (file)
index 23e0a99..0000000
+++ /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
index 0b60af5..bef0ed2 100644 (file)
@@ -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",