Esempio n. 1
0
 def test_mock_all_pings_pass(self):
     """Verifies ping success scenario via mocked returncode 0
     """
     mpts.get_returncode = Mock()
     # mock returncode - all IP addresses pass ping
     mpts.get_returncode.return_value = 0
     result = mpts.main([])
     self.assertFalse(result[0])  # failed_ips1 is empty
     self.assertFalse(result[1])  # failed_ips2 is empty
     self.assertFalse(result[2])  # failed_ips1_excl_octets is empty
     self.assertFalse(result[3])  # failed_ips2_excl_octets is empty
     self.assertFalse(result[4])  # failed_ips_common_octets is empty
Esempio n. 2
0
    def test_no_options(self):
        """Verifies that no optional arguments works as expected.
        """
        mpts.get_returncode = Mock()
        # mock returncode - all IP addresses fail ping
        mpts.get_returncode.return_value = 1

        result = mpts.main([])  # default subnets with no octets skipped
        # default CIDR1/24 is correctly pinged
        self.assertTrue(all(['192.168.1.' in ip[1] for ip in result[0]]))
        # default CIDR2/24 is correctly pinged
        self.assertTrue(all(['192.168.2.' in ip[1] for ip in result[1]]))
        # no octets skipped
        self.assertTrue(len(result[4]) == 255)
Esempio n. 3
0
 def test_mock_all_pings_fail(self):
     """Verifies ping failure scenario via mocked returncode 1
     """
     mpts.get_returncode = Mock()
     # mock returncode - all IP addresses fail ping
     mpts.get_returncode.return_value = 1
     result = mpts.main([])
     # failed_ips1 is full
     self.assertTrue(len(result[0]) == 255)
     # failed_ips2 is full
     self.assertTrue(len(result[1]) == 255)
     # failed_ips1_excl_octets is empty
     self.assertFalse(result[2])
     # failed_ips2_excl_octets is empty
     self.assertFalse(result[3])
     # failed_ips_common_octets is full
     self.assertTrue(len(result[4]) == 255)
Esempio n. 4
0
    def test_all_options(self):
        """Verifies that all optional arguments work as expected:
           --cid1, --cidr2, --skip
        """
        mpts.get_returncode = Mock()
        # mock returncode - all IP addresses fail ping
        mpts.get_returncode.return_value = 1

        # custom subnets and skip
        result = mpts.main([
            '--cidr1', '192.168.7.0/24', '--cidr2', '192.168.8.0/24', '--skip',
            '42'
        ])
        # custom CIDR1/24 is correctly pinged
        self.assertTrue(all(['192.168.7.' in ip[1] for ip in result[0]]))
        # custom CIDR2/24 is correctly pinged
        self.assertTrue(all(['192.168.8.' in ip[1] for ip in result[1]]))
        # skipped octet is skipped (not tested)
        self.assertTrue(42 not in result[2] and 42 not in result[3]
                        and 42 not in result[4])
Esempio n. 5
0
 def test_mock_many_pings_fail(self):
     """Verifies mixed success/failure results via mock with side_effect.
        The side_effect introduces a combination of numerous failures and
        successes.
        The accurate reporting of failures is verified via verify_octets.
     """
     mpts.get_returncode = Mock()
     side_effect_values = [(lambda x: 1 if x < 300 else 0)
                           for x in range(2000)]
     # the first 300 ping attempts fail, the rest succeed
     mpts.get_returncode.side_effect = side_effect_values
     result = mpts.main([])
     self.assertTrue(len(result[0]) > 5)  # failed_ips1 has numerous values
     self.assertTrue(len(result[1]) > 5)  # failed_ips2 has numerous values
     # note: failed_ips1_excl_octets is indeterminate due to mt timing
     # note: failed_ips2_excl_octets is indeterminate due to mt timing
     # failed_ips_common_octets has numerous values
     self.assertTrue(len(result[4]) > 5)
     # verify the detailed results are as expected
     self.verify_octets(result)