Ejemplo n.º 1
0
    def test_log_funcs(self):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.__log_info__("Test Message")
        jdm_vnf_obj.__log_warning__("Test Message")
        jdm_vnf_obj.__log_error__("Test Message")
Ejemplo n.º 2
0
    def test_disconnect_ssh_to_vnf_via_jdm_exception_2(self, patch_disconnect):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_ssh_handles = "Test"

        try:
            self.assertEqual(
                jdm_vnf_obj.disconnect_ssh_to_vnf_via_jdm("r0", "new-centos"),
                True)
        except Exception as err:
            self.assertRegex(err.args[0], ".*test-msg.*")
Ejemplo n.º 3
0
    def test_disconnect_console_to_vnf_via_jdm_exception_1(
            self, patch_disconnect, patch_exec):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_console_handles = "test"

        try:
            self.assertEqual(
                jdm_vnf_obj.disconnect_console_to_vnf_via_jdm("r0", "centos"),
                True)
        except Exception as err:
            self.assertRegex(
                err.args[0],
                ".*Exception Raised in disconnect_console_to_vn.*")
Ejemplo n.º 4
0
    def test_disconnect_ssh_to_vnf_via_jdm_disconnect_failed(
            self, patch_disconnect):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_ssh_handles = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"] = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"]["centos"] = 1

        try:
            self.assertEqual(
                jdm_vnf_obj.disconnect_ssh_to_vnf_via_jdm("r0", "centos"),
                True)
        except Exception as err:
            self.assertRegex(err.args[0], ".*Disconnect.*failed.*")
Ejemplo n.º 5
0
    def test_disconnect_ssh_to_vnf_via_jdm(self, patch_disconnect):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_ssh_handles = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"] = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"]["centos"] = None

        self.assertEqual(
            jdm_vnf_obj.disconnect_ssh_to_vnf_via_jdm("r0", "centos"), True)
        self.assertEqual(
            jdm_vnf_obj.disconnect_ssh_to_vnf_via_jdm("r0", "new-centos"),
            True)
        self.assertEqual(
            jdm_vnf_obj.disconnect_ssh_to_vnf_via_jdm("r1", "new-centos"),
            True)
Ejemplo n.º 6
0
    def test_execute_command_on_vnf(self, patch_exec_shell):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_console_handles = {}
        jdm_vnf_obj.vnf_console_handles["r0"] = {}
        jdm_vnf_obj.vnf_console_handles["r0"]["centos"] = 1

        jdm_vnf_obj.vnf_ssh_handles = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"] = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"]["centos"] = None

        output = "test_output"
        self.assertEqual(
            jdm_vnf_obj.execute_command_on_vnf("r0",
                                               "centos",
                                               "test-cmd",
                                               console=True), (True, output))

        try:
            self.assertEqual(
                jdm_vnf_obj.execute_command_on_vnf("r0",
                                                   "centos",
                                                   "test-cmd",
                                                   console=False),
                (True, output))
        except Exception as err:
            self.assertRegex(err.args[0], ".*No Handle.*")

        try:
            self.assertEqual(
                jdm_vnf_obj.execute_command_on_vnf("r0",
                                                   "centos",
                                                   "test-cmd",
                                                   console=False,
                                                   mode="test"),
                (True, output))
        except Exception as err:
            self.assertRegex(err.args[0], ".*Unsupported.*")
Ejemplo n.º 7
0
    def test_disconnect_console_to_vnf_via_jdm(self, patch_disconnect,
                                               patch_exec):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_console_handles = {}
        jdm_vnf_obj.vnf_console_handles["r0"] = {}
        jdm_vnf_obj.vnf_console_handles["r0"]["centos"] = 1
        jdm_vnf_obj.vnf_console_handles["r0"]["new-centos"] = None

        jdm_vnf_obj.vnf_type = {}
        jdm_vnf_obj.vnf_type["r0"] = {}
        jdm_vnf_obj.vnf_type["r0"]["centos"] = "junos"
        jdm_vnf_obj.vnf_type["r0"]["new-centos"] = None

        self.assertEqual(
            jdm_vnf_obj.disconnect_console_to_vnf_via_jdm("r0", "centos"),
            True)
        self.assertEqual(
            jdm_vnf_obj.disconnect_console_to_vnf_via_jdm("r0", "new-centos"),
            True)
Ejemplo n.º 8
0
    def test_get_vnf_handle(self):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_console_handles = {}
        jdm_vnf_obj.vnf_console_handles["r0"] = {}
        jdm_vnf_obj.vnf_console_handles["r0"]["centos"] = 1

        jdm_vnf_obj.vnf_ssh_handles = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"] = {}
        jdm_vnf_obj.vnf_ssh_handles["r0"]["centos"] = None

        self.assertEqual(
            jdm_vnf_obj.get_vnf_handle("r0", "centos", mode="console"),
            (True, 1))

        try:
            self.assertEqual(
                jdm_vnf_obj.get_vnf_handle("r0", "cento", mode="console"),
                (True, 1))
        except Exception as err:
            self.assertRegex(err.args[0], ".*No Handle.*")
Ejemplo n.º 9
0
    def test_disconnect_console_to_vnf_via_jdm_exception_3(
            self, patch_disconnect, patch_exec):

        jdm_vnf_obj = jdm_vnf()
        builtins.t = MagicMock()
        builtins.t.log = MagicMock()

        jdm_vnf_obj.vnf_console_handles = {}
        jdm_vnf_obj.vnf_console_handles["r0"] = {}
        jdm_vnf_obj.vnf_console_handles["r0"]["centos"] = 1
        jdm_vnf_obj.vnf_console_handles["r0"]["new-centos"] = None

        jdm_vnf_obj.vnf_type = {}
        jdm_vnf_obj.vnf_type["r0"] = {}
        jdm_vnf_obj.vnf_type["r0"]["centos"] = "junos"
        jdm_vnf_obj.vnf_type["r0"]["new-centos"] = None

        try:
            self.assertEqual(
                jdm_vnf_obj.disconnect_console_to_vnf_via_jdm("r0", "centos"),
                True)
        except Exception as err:
            self.assertRegex(err.args[0],
                             ".*Closing Console Handle failed to VNF.*")