示例#1
0
 def test_unix_new_ssh_oth(self, patch1, patch2):
     patch1.client = MagicMock
     patch1.client.recv = MagicMock(return_value=b'sun-solaris-bsd1 $')
     self.assertRaises(
         Exception, lambda: Unix(host="dummy-freebsd",
                                 connect_mode='ssh',
                                 os='unix',
                                 model='os360'))
示例#2
0
    def test_unix_new_param2(self, patch1, patch2, patch3, patch4, patch5,
                             patch6):
        obj = MagicMock()
        patch6.return_value = obj
        obj.host = 'host1'

        patch1.client = MagicMock
        patch1.client.recv = MagicMock(return_value=b'Linux vm-soa2-bsd1.'
                                       b'englab.juniper $')
        ab = Unix(host="dummy-freebsd",
                  connect_mode='ssh',
                  osname='unix',
                  user='',
                  ssh_key_file='')
        #self.assertIsInstance(ab, CentOS)
        self.assertEqual(ab, obj)
示例#3
0
    def test_unix_new_ssh_linux(self, patch1, patch2, patch3, patch4, patch5):
        obj = MagicMock()
        patch5.return_value = obj
        obj.host = 'host1'

        # TBA line 44: just test existnce not null value
        patch1.client = MagicMock
        patch1.client.recv = MagicMock(return_value=b'Linux tot-linux1 $')
        ab = Unix(host="dummy-freebsd",
                  connect_mode='ssh',
                  os='unix',
                  model='linux',
                  user=False,
                  osname='linux',
                  ssh_key_file='')
        #self.assertIsInstance(ab, CentOS)
        self.assertEqual(ab, obj)
示例#4
0
文件: node.py 项目: SrijaGupta/file
    def __init__(self, node_data):
        """
        Base class for node, 'controller' is often analogous to RE
        :param node_dict:
            **REQUIRED** node_data of node
        :return: node object based os and model
        """

        self.controllers = dict()
        self.current_controller = None
        self.current_controller_str = None
        # Stores the role (e.g. member0/member1) if applicable, otherwise 'null'
        if 'role' in node_data.keys():
            self.role = node_data['role']
        else:
            self.role = 'null'

        #supports multiple controllers (typically JUNOS only)
        for controller_name in node_data['controllers'].keys():
            if 'vc' in node_data.keys():
                node_data['controllers'][controller_name]['vc'] = node_data[
                    'vc']
            else:
                node_data['controllers'][controller_name]['vc'] = False

        if 'connect' in node_data.keys() and node_data['connect']:
            for controller_name in node_data['controllers'].keys():
                try:
                    if 'connect' in node_data['controllers'][controller_name].keys() and \
                            node_data['controllers'][controller_name]['connect']:
                        if node_data['controllers'][controller_name][
                                'osname'].upper() == 'JUNOS':
                            from jnpr.toby.hldcl.juniper.junos import Junos
                            self.controllers[controller_name] = Junos(
                                **node_data['controllers'][controller_name],
                                re_name=controller_name)
                        elif node_data['controllers'][controller_name]['osname'].upper() == 'UNIX' or\
                            node_data['controllers'][controller_name]['osname'].upper() == 'LINUX' or \
                            node_data['controllers'][controller_name]['osname'].upper() == 'CENTOS' or \
                            node_data['controllers'][controller_name]['osname'].upper() == 'UBUNTU' or \
                            node_data['controllers'][controller_name]['osname'].upper() == 'SIFOS-LINUX' or \
                            node_data['controllers'][controller_name]['osname'].upper() == 'FREEBSD':
                            from jnpr.toby.hldcl.unix.unix import Unix
                            self.controllers[controller_name] = Unix(
                                **node_data['controllers'][controller_name])
                        elif node_data['controllers'][controller_name][
                                'osname'].upper() == 'WINDOWS':
                            if 'selenium' in node_data['controllers'][controller_name] and \
                                             node_data['controllers'][controller_name]['selenium'] == "enable":
                                from jnpr.toby.hldcl.windows.selenium.selenium import Selenium
                                self.controllers[controller_name] = Selenium(
                                    **node_data['controllers']
                                    [controller_name])
                            else:
                                from jnpr.toby.hldcl.windows.windows import Windows
                                self.controllers[controller_name] = Windows(
                                    **node_data['controllers']
                                    [controller_name])
                        elif node_data['controllers'][controller_name][
                                'osname'].upper() == 'IOS':
                            from jnpr.toby.hldcl.cisco.cisco import Cisco
                            self.controllers[controller_name] = Cisco(
                                **node_data['controllers'][controller_name])
                        elif node_data['controllers'][controller_name][
                                'osname'].upper() == 'BROCADE':
                            from jnpr.toby.hldcl.brocade.brocade import Brocade
                            self.controllers[controller_name] = Brocade(
                                **node_data['controllers'][controller_name])
                        elif node_data['controllers'][controller_name][
                                'osname'].upper() == 'SRC':
                            from jnpr.toby.hldcl.src.src import Src
                            self.controllers[controller_name] = Src(
                                **node_data['controllers'][controller_name])
                        else:
                            raise TobyException(
                                "OS is not supported " +
                                self.controllers['controller_name']['osname'])
                        setattr(self.controllers[controller_name],
                                'controllers_data',
                                node_data['controllers'][controller_name])
                    else:
                        t.log("Skipping the connection for '" +
                              controller_name + "'")
                        # sleep required to prevent multithreading race condition
                        time.sleep(1)
                except Exception as exp:
                    raise TobyException("%s(%s) " %
                                        (str(exp), str(controller_name)))

            if self.controllers:
                self._set_current_controller()
示例#5
0
 def test_unix_flavour_exception2(self, patch1, patch2):
     os.environ['version'] = 'junos'
     self.assertRaises(
         Exception, lambda: Unix(
             host="dummy-freebsd", connect_mode='telnet', os='unix'))
示例#6
0
 def test_unix_init_execption(self, patch1):
     self.assertRaises(Exception,
                       lambda: Unix(connect_mode='ssh', os='unix'))
示例#7
0
    def test_unix_get_unix_flavour(self, freebsd_patch, centos_patch,
                                   host_patch, telnetconn_patch, logging_patch,
                                   select_patch, sshconn_patch):

        import builtins
        builtins.t = self
        t.log = MagicMock()

        telnetconn_patch.return_value.expect.return_value = [
            'test1', 'test2', b'Linux'
        ]
        obj1 = MagicMock()
        centos_patch.return_value = obj1
        ab = Unix(host="dummy-freebsd",
                  connect_mode='telnet',
                  osname='unix',
                  user='')
        self.assertEqual(ab, obj1)

        telnetconn_patch.return_value.expect.return_value = [
            'test1', 'test2', b'FreeBSD'
        ]
        obj2 = MagicMock()
        freebsd_patch.return_value = obj2
        ab = Unix(host="dummy-freebsd",
                  connect_mode='telnet',
                  osname='unix',
                  user='******',
                  password='******')
        self.assertEqual(ab, obj2)

        # Exception
        telnetconn_patch.return_value.expect.return_value = [
            'test1', 'test2', b'fedora'
        ]
        try:
            ab = Unix(host="dummy-freebsd",
                      connect_mode='telnet',
                      osname='unix',
                      user='')
        except Exception as exp:
            self.assertEqual(exp.args[0],
                             'Invalid Unix model detected: \'Unknown\'')

        # Exception
        sshconn_patch.return_value.client.recv.side_effect = [b'test', b'>']
        try:
            ab = Unix(host="dummy-freebsd",
                      connect_mode='ssh',
                      osname='unix',
                      user='',
                      ssh_key_file='')
        except Exception as exp:
            self.assertEqual(exp.args[0],
                             'Invalid Unix model detected: \'Unknown\'')

        # Exception
        sshconn_patch.side_effect = Exception
        try:
            ab = Unix(host="dummy-freebsd",
                      connect_mode='ssh',
                      osname='unix',
                      user='')
        except Exception as exp:
            self.assertEqual(exp.args[0],
                             'Cannot connect to unix Device dummy-freebsd')