Esempio n. 1
0
    def test_update_configuration_record_partial_match_pass(self):
        """Verify existing syslog server record partial match results in an update request."""
        initial = {
            "state": "present",
            "ssid": "1",
            "address": "192.168.1.1",
            "port": "514",
            "protocol": "tcp",
            "components": ["auditLog"]
        }
        expected = [{
            "id": "123456",
            "serverAddress": "192.168.1.1",
            "port": 514,
            "protocol": "udp",
            "components": [{
                "type": "auditLog"
            }]
        }]

        self._set_args(initial)
        syslog = Syslog()

        with mock.patch(self.REQ_FUNC,
                        side_effect=[(200, expected), (200, None)]):
            updated = syslog.update_configuration()
            self.assertTrue(updated)
Esempio n. 2
0
    def test_test_configuration_fail(self):
        """Validate test_configuration fails when request exception is thrown."""
        initial = {"state": "present",
                   "ssid": "1",
                   "address": "192.168.1.1",
                   "port": "514",
                   "protocol": "udp",
                   "components": ["auditLog"]}
        self._set_args(initial)
        syslog = Syslog()

        with self.assertRaisesRegexp(AnsibleFailJson, r"We failed to send test message!"):
            with mock.patch(self.REQ_FUNC, side_effect=Exception()):
                with mock.patch("time.sleep", return_value=None):  # mocking sleep is not working
                    syslog.test_configuration(self.REQUIRED_PARAMS)