Beispiel #1
0
 def test_get_check_banners(self):
     for dut in self.duts:
         motd_banner_value = random_string() + "\n"
         login_banner_value = random_string() + "\n"
         dut.config([dict(cmd="banner motd", input=motd_banner_value)])
         dut.config([dict(cmd="banner login", input=login_banner_value)])
         resp = dut.api('system').get()
         self.assertEqual(resp['banner_login'], login_banner_value.rstrip())
         self.assertEqual(resp['banner_motd'], motd_banner_value.rstrip())
Beispiel #2
0
    def test_config_with_multiple_multilines(self):
        commands = [random_string(),
                    ('banner login MULTILINE:This is a new banner\n'
                    'with different lines!!!'),
                    random_string()]

        self.node.run_commands = Mock(return_value=[{}, {}, {}, {}])
        result = self.node.config(commands)
        self.assertEqual(result, [{}, {}, {}])
Beispiel #3
0
 def test_set_banner_motd(self):
     for dut in self.duts:
         banner_value = random_string()
         dut.config([dict(cmd="banner motd", input=banner_value)])
         self.assertIn(banner_value, dut.running_config)
         banner_api_value = random_string()
         resp = dut.api('system').set_banner("motd", banner_api_value)
         self.assertTrue(resp, 'dut=%s' % dut)
         self.assertIn(banner_api_value, dut.running_config)
Beispiel #4
0
    def test_config_with_multiple_multilines(self):
        commands = [random_string(),
                    ('banner login MULTILINE:This is a new banner\n'
                     'with different lines!!!'),
                    random_string()]

        self.node.run_commands = Mock(return_value=[{}, {}, {}, {}])
        result = self.node.config(commands)
        self.assertEqual(result, [{}, {}, {}])
 def test_set_banner_motd(self):
     for dut in self.duts:
         banner_value = random_string()
         dut.config([dict(cmd="banner motd",
                          input=banner_value)])
         self.assertIn(banner_value, dut.running_config)
         banner_api_value = random_string()
         resp = dut.api('system').set_banner("motd", banner_api_value)
         self.assertTrue(resp, 'dut=%s' % dut)
         self.assertIn(banner_api_value, dut.running_config)
Beispiel #6
0
 def test_set_banner_login(self):
     for dut in self.duts:
         banner_value = random_string()
         dut.config([dict(cmd="banner login", input=banner_value)])
         self.assertIn(banner_value, dut.running_config)
         banner_api_value = random_string()
         resp = dut.api('system').set_banner("login", banner_api_value)
         self.assertTrue(resp, 'dut=%s' % dut)
         self.assertIn(banner_api_value, dut.running_config)
         config_login_banner = dut.api('system').get()['banner_login']
         self.assertTrue(config_login_banner, banner_api_value.strip())
 def test_set_banner_login(self):
     for dut in self.duts:
         banner_value = random_string()
         dut.config([dict(cmd="banner login",
                          input=banner_value)])
         self.assertIn(banner_value, dut.running_config)
         banner_api_value = random_string()
         resp = dut.api('system').set_banner("login", banner_api_value)
         self.assertTrue(resp, 'dut=%s' % dut)
         self.assertIn(banner_api_value, dut.running_config)
         config_login_banner = dut.api('system').get()['banner_login']
         self.assertTrue(config_login_banner, banner_api_value.strip())
Beispiel #8
0
 def test_set_trunk_groups(self):
     for dut in self.duts:
         vid = str(random_int(2, 4094))
         tg1 = random_string(maxchar=10)
         tg2 = random_string(maxchar=10)
         tg3 = random_string(maxchar=10)
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid,
                     'trunk group %s' % tg1, 'trunk group %s' % tg2])
         result = dut.api('vlans').set_trunk_groups(vid, [tg1, tg3])
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan %s trunk group' % vid)
         config = sorted(config[0]['trunkGroups'][vid]['names'])
         self.assertEqual(sorted([tg1, tg3]), config)
Beispiel #9
0
 def test_load_config_for_connection_with_env(self):
     os.environ['EAPI_CONF'] = get_fixture('eapi.conf')
     pyeapi.client.load_config(random_string())
     cfg = pyeapi.client.config.get_connection('test1')
     self.assertEqual(cfg['host'], '192.168.1.16')
     self.assertEqual(cfg['username'], 'eapi')
     self.assertEqual(cfg['password'], 'password')
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.tomcat_daemon = testlib.TestDaemon("/etc/init.d/" + exe)
        self.users_file = "/etc/" + exe + "/tomcat-users.xml"
        self.html_page = "/var/lib/" + exe + "/webapps/ROOT/test.html"
        self.webapp_dir = "/var/lib/" + exe + "/webapps"
        self.war = ""

        self.admin_user = "******"
        #self.admin_pass = "******"
        self.admin_pass = testlib.random_string(10)
        testlib.config_replace(self.users_file, "", True)
        self.manager_group = "manager"
        if exe in ["tomcat7", "tomcat8"]:
            self.manager_group = "manager-gui"
        user_config = 's/^<tomcat-users>/<tomcat-users>\\n<role rolename=\"%s\"\/>\\n<user username=\"%s\" password=\"%s\" roles=\"%s\"\/>\\n/' % (
            self.manager_group, self.admin_user, self.admin_pass,
            self.manager_group)
        if exe in ["tomcat8"]:
            user_config = 's/^<\/tomcat-users>/<role rolename=\"%s\"\/>\\n<user username=\"%s\" password=\"%s\" roles=\"%s\"\/>\\n<\/tomcat-users>\\n/' % (
                self.manager_group, self.admin_user, self.admin_pass,
                self.manager_group)

        subprocess.call(['sed', '-i', user_config, self.users_file])
        subprocess.call(['chgrp', exe, self.users_file])

        self.tomcat_daemon.restart()
Beispiel #11
0
 def test_load_config_for_connection_with_env(self):
     os.environ['EAPI_CONF'] = get_fixture('eapi.conf')
     pyeapi.client.load_config(random_string())
     cfg = pyeapi.client.config.get_connection('test1')
     self.assertEqual(cfg['host'], '192.168.1.16')
     self.assertEqual(cfg['username'], 'eapi')
     self.assertEqual(cfg['password'], 'password')
Beispiel #12
0
 def test_set_description_with_value(self):
     value = random_string()
     cmds = [
         'route-map TEST permit 10', 'no description',
         'description %s' % value
     ]
     func = function('set_description', 'TEST', 'permit', 10, value)
     self.eapi_positive_config_test(func, cmds)
 def test_set_hostname_with_value(self):
     for dut in self.duts:
         dut.config('default hostname')
         value = random_string()
         response = dut.api('system').set_hostname(value)
         self.assertTrue(response, 'dut=%s' % dut)
         value = 'hostname %s' % value
         self.assertIn(value, dut.running_config)
Beispiel #14
0
 def test_config_multiple_commands(self):
     for dut in self.duts:
         commands = list()
         for i in range(1, random_int(10, 200)):
             commands.append('hostname %s' % random_string(5, 20))
         result = dut.config(commands[:])
         self.assertIsInstance(result, list, 'dut=%s' % dut)
         self.assertEqual(len(result), len(commands), 'dut=%s' % dut)
Beispiel #15
0
 def test_set_hostname_with_value(self):
     for dut in self.duts:
         dut.config('default hostname')
         value = random_string()
         response = dut.api('system').set_hostname(value)
         self.assertTrue(response, 'dut=%s' % dut)
         value = 'hostname %s' % value
         self.assertIn(value, dut.running_config)
Beispiel #16
0
 def test_config_multiple_commands(self):
     for dut in self.duts:
         commands = list()
         for i in range(1, random_int(10, 200)):
             commands.append('hostname %s' % random_string(5, 20))
         result = dut.config(commands[:])
         self.assertIsInstance(result, list, 'dut=%s' % dut)
         self.assertEqual(len(result), len(commands), 'dut=%s' % dut)
Beispiel #17
0
    def test_enable_with_single_command(self):
        command = random_string()
        response = ['enable', command]

        self.connection.execute.return_value = {'result': list(response)}
        result = self.node.enable(command)

        self.connection.execute.assert_called_once_with(response, 'json')
        self.assertEqual(command, result[0]['result'])
Beispiel #18
0
    def test_enable_with_single_command(self):
        command = random_string()
        response = ['enable', command]

        self.connection.execute.return_value = {'result': list(response)}
        result = self.node.enable(command)

        self.connection.execute.assert_called_once_with(response, 'json')
        self.assertEqual(command, result[0]['result'])
 def test_set_description(self):
     for dut in self.duts:
         text = random_string()
         intf = random_interface(dut)
         result = dut.api('interfaces').set_description(intf, text)
         self.assertTrue(result)
         config = dut.run_commands('show interfaces %s' % intf)
         config = config[0]['interfaces'][intf]
         self.assertEqual(config['description'], text)
Beispiel #20
0
 def test_set_description(self):
     for dut in self.duts:
         text = random_string()
         intf = random_interface(dut)
         result = dut.api('interfaces').set_description(intf, text)
         self.assertTrue(result)
         config = dut.run_commands('show interfaces %s' % intf)
         config = config[0]['interfaces'][intf]
         self.assertEqual(config['description'], text)
Beispiel #21
0
 def test_default(self):
     for dut in self.duts:
         vid = str(random_int(2, 4095))
         name = random_string(maxchar=20)
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid,
                     'vlan %s' % vid, 'name %s' % name])
         result = dut.api('vlans').default(vid)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertNotIn(vid, config[0]['vlans'], 'dut=%s' % dut)
Beispiel #22
0
 def test_add_trunk_group(self):
     for dut in self.duts:
         tg = random_string(maxchar=32)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid, 'no trunk group'])
         result = dut.api('vlans').add_trunk_group(vid, tg)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan trunk group')
         self.assertIn(tg, config[0]['trunkGroups'][vid]['names'],
                       'dut=%s' % dut)
Beispiel #23
0
 def test_set_name(self):
     for dut in self.duts:
         name = random_string(maxchar=20)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid])
         result = dut.api('vlans').set_name(vid, name)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertEqual(name, config[0]['vlans'][vid]['name'],
                          'dut=%s' % dut)
 def test_set_description_negate(self):
     for dut in self.duts:
         text = random_string()
         intf = random_interface(dut)
         dut.config(['interface %s' % intf, 'description %s' % text])
         result = dut.api('interfaces').set_description(intf, disable=True)
         self.assertTrue(result)
         config = dut.run_commands('show interfaces %s' % intf)
         config = config[0]['interfaces'][intf]
         self.assertEqual(config['description'], '')
Beispiel #25
0
 def test_add_trunk_group(self):
     for dut in self.duts:
         tg = random_string(maxchar=32)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid, 'no trunk group'])
         result = dut.api('vlans').add_trunk_group(vid, tg)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan trunk group')
         self.assertIn(tg, config[0]['trunkGroups'][vid]['names'],
                       'dut=%s' % dut)
Beispiel #26
0
 def test_set_name(self):
     for dut in self.duts:
         name = random_string(maxchar=20)
         vid = str(random_int(2, 4095))
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid])
         result = dut.api('vlans').set_name(vid, name)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands('show vlan')
         self.assertEqual(name, config[0]['vlans'][vid]['name'],
                          'dut=%s' % dut)
 def test_set_description_negate(self):
     for dut in self.duts:
         text = random_string()
         intf = random_interface(dut)
         dut.config(['interface %s' % intf, 'description %s' % text])
         result = dut.api('interfaces').set_description(intf, disable=True)
         self.assertTrue(result)
         config = dut.run_commands('show interfaces %s' % intf)
         config = config[0]['interfaces'][intf]
         self.assertEqual(config['description'], '')
Beispiel #28
0
    def test_config_single_command(self):
        for dut in self.duts:
            hostname = 'hostname %s' % random_string(5, 50)
            result = dut.config(hostname)
            self.assertIsInstance(result, list, 'dut=%s' % dut)
            self.assertEqual(len(result), 1, 'dut=%s' % dut)
            self.assertEqual(result[0], {}, 'dut=%s' % dut)

            result = dut.run_commands('show running-config | include %s$' %
                                      hostname, 'text')
            self.assertEqual(result[0]['output'].strip(), hostname)
Beispiel #29
0
 def test_set_trunk_groups_default(self):
     for dut in self.duts:
         vid = str(random_int(2, 4094))
         tg = random_string()
         dut.config(['no vlan %s' % vid, 'vlan %s' % vid,
                     'trunk group %s' % tg])
         result = dut.api('vlans').set_trunk_groups(vid, default=True)
         self.assertTrue(result, 'dut=%s' % dut)
         cmd = 'show running-config section vlan %s' % vid
         config = dut.run_commands(cmd, 'text')
         self.assertNotIn('trunk group', config[0]['output'])
Beispiel #30
0
    def test_config_single_command(self):
        for dut in self.duts:
            hostname = 'hostname %s' % random_string(5, 50)
            result = dut.config(hostname)
            self.assertIsInstance(result, list, 'dut=%s' % dut)
            self.assertEqual(len(result), 1, 'dut=%s' % dut)
            self.assertEqual(result[0], {}, 'dut=%s' % dut)

            result = dut.run_commands(
                'show running-config | include %s$' % hostname, 'text')
            self.assertEqual(result[0]['output'].strip(), hostname)
 def test_set_mtu_invalid_value_raises_value_error(self):
     for intf in self.INTERFACES:
         for value in [67, 65536, random_string()]:
             func = function('set_mtu', intf, value)
             self.eapi_exception_config_test(func, ValueError)
         for value in [None]:
             # If command_builder fails because value is None, put None
             # in the first loop to check for value error, and remove
             # this second loop
             cmds = ['interface %s' % intf, 'no mtu']
             func = function('set_mtu', intf, value)
             self.eapi_positive_config_test(func, cmds)
 def test_set_mtu_invalid_value_raises_value_error(self):
     for intf in self.INTERFACES:
         for value in [67, 65536, random_string()]:
             func = function('set_mtu', intf, value)
             self.eapi_exception_config_test(func, ValueError)
         for value in [None]:
             # If command_builder fails because value is None, put None
             # in the first loop to check for value error, and remove
             # this second loop
             cmds = ['interface %s' % intf, 'no mtu']
             func = function('set_mtu', intf, value)
             self.eapi_positive_config_test(func, cmds)
 def generate_ssh_keys(self, keytype='rsa', password=None):
     if not password:
         self.privkey_pass = testlib.random_string(8)
     else:
         self.privkey_pass = password
     command = self._cmd_as_user([
         "ssh-keygen", "-q", "-N", self.privkey_pass, '-t', keytype, '-f',
         self.user.home + "/.ssh/id_" + keytype
     ])
     expected = 0
     rc, cmp_out = self.shell_cmd(command)
     self.assertEquals(expected, rc, cmp_out)
Beispiel #34
0
 def test_set_hostname(self):
     for state in ['config', 'negate', 'default']:
         value = random_string()
         if state == 'config':
             cmds = 'hostname %s' % value
             func = function('set_hostname', value)
         elif state == 'negate':
             cmds = 'no hostname'
             func = function('set_hostname', disable=True)
         elif state == 'default':
             cmds = 'default hostname'
             func = function('set_hostname', value=value, default=True)
         self.eapi_positive_config_test(func, cmds)
Beispiel #35
0
 def test_set_description(self):
     for dut in self.duts:
         text = random_string()
         dut.config(['no route-map TEST deny 10',
                     'route-map TEST deny 10'])
         api = dut.api('routemaps')
         self.assertNotIn('description %s' % text,
                          api.get_block('route-map TEST deny 10'))
         result = dut.api('routemaps').set_description('TEST', 'deny', 10,
                                                       text)
         self.assertTrue(result)
         self.assertIn('description %s' % text,
                       api.get_block('route-map TEST deny 10'))
 def test_set_hostname(self):
     for state in ['config', 'negate', 'default']:
         value = random_string()
         if state == 'config':
             cmds = 'hostname %s' % value
             func = function('set_hostname', value)
         elif state == 'negate':
             cmds = 'no hostname'
             func = function('set_hostname', disable=True)
         elif state == 'default':
             cmds = 'default hostname'
             func = function('set_hostname', value=value, default=True)
         self.eapi_positive_config_test(func, cmds)
Beispiel #37
0
 def test_set_description(self):
     for dut in self.duts:
         text = random_string()
         dut.config(['no route-map TEST deny 10',
                     'route-map TEST deny 10'])
         api = dut.api('routemaps')
         self.assertNotIn('description %s' % text,
                          api.get_block('route-map TEST deny 10'))
         result = dut.api('routemaps').set_description('TEST', 'deny', 10,
                                                       text)
         self.assertTrue(result)
         self.assertIn('description %s' % text,
                       api.get_block('route-map TEST deny 10'))
Beispiel #38
0
 def test_set_name(self):
     for state in ['config', 'negate', 'default']:
         vid = random_vlan()
         name = random_string()
         if state == 'config':
             cmds = ['vlan %s' % vid, 'name %s' % name]
             func = function('set_name', vid, name)
         elif state == 'negate':
             cmds = ['vlan %s' % vid, 'no name']
             func = function('set_name', vid, disable=True)
         elif state == 'default':
             cmds = ['vlan %s' % vid, 'default name']
             func = function('set_name', vid, default=True)
         self.eapi_positive_config_test(func, cmds)
Beispiel #39
0
 def test_set_name(self):
     for state in ['config', 'negate', 'default']:
         vid = random_vlan()
         name = random_string()
         if state == 'config':
             cmds = ['vlan %s' % vid, 'name %s' % name]
             func = function('set_name', vid, name)
         elif state == 'negate':
             cmds = ['vlan %s' % vid, 'no name']
             func = function('set_name', vid)
         elif state == 'default':
             cmds = ['vlan %s' % vid, 'default name']
             func = function('set_name', vid, default=True)
         self.eapi_positive_config_test(func, cmds)
    def test_08_insert_delete_multiple(self):
        ''' Verify 'insert_multiple' and 'delete_multiple' functionality
        '''
        create_num = 5
        data = []
        for _ in range(create_num):
            description = 'Systest Generated: %s' % random_string(5, 10)
            data.append({'short_description': description})

        resp = self.table.insert_multiple(data)
        self.assertEqual(len(resp), create_num)

        query_str = 'short_descriptionSTARTSWITHSystest Generated:'
        resp = self.table.delete_multiple(query_str)
        self.assertEqual(resp[0]['count'], create_num)
Beispiel #41
0
 def test_set_description(self):
     for dut in self.duts:
         description = random_string()
         dut.config(['no vrf definition blah', 'vrf definition blah'])
         result = dut.api('vrfs').set_description('blah', description)
         self.assertTrue(result, 'dut=%s' % dut)
         command = 'show running-config section vrf'
         config = dut.run_commands(command, encoding='text')
         self.assertIn('description %s' % description, config[0]['output'],
                       'dut=%s' % dut)
         result = dut.api('vrfs').set_description('blah', default=True)
         self.assertTrue(result, 'dut=%s' % dut)
         config = dut.run_commands(command, encoding='text')
         self.assertNotIn('description %s' % description,
                          config[0]['output'], 'dut=%s' % dut)
         dut.config(['no vrf definition blah'])
Beispiel #42
0
    def test_enable_with_multiple_commands(self):
        commands = list()
        for i in range(0, random_int(2, 5)):
            commands.append(random_string())

        def execute_response(cmds, *args):
            return {'result': [x for x in cmds]}

        self.connection.execute.side_effect = execute_response

        responses = self.node.enable(commands)

        self.assertEqual(self.connection.execute.call_count, len(commands))

        expected_calls = [call(['enable', cmd], 'json') for cmd in commands]
        self.assertEqual(self.connection.execute.mock_calls, expected_calls)

        for index, response in enumerate(responses):
            self.assertEqual(commands[index], response['result'])
Beispiel #43
0
    def test_enable_with_multiple_commands(self):
        commands = list()
        for i in range(0, random_int(2, 5)):
            commands.append(random_string())

        def execute_response(cmds, *args):
            return {'result': [x for x in cmds]}

        self.connection.execute.side_effect = execute_response

        responses = self.node.enable(commands)

        self.assertEqual(self.connection.execute.call_count, len(commands))

        expected_calls = [call(['enable', cmd], 'json') for cmd in commands]
        self.assertEqual(self.connection.execute.mock_calls, expected_calls)

        for index, response in enumerate(responses):
            self.assertEqual(commands[index], response['result'])
Beispiel #44
0
    def test_create(self):
        # Test passing in a full set of parameters to 'create'
        # Some parameters may be not set: None
        for ip_dest in IP_DESTS:
            # Get the parameters for the call
            (next_hop, next_hop_ip) = choice(NEXT_HOPS)
            distance = choice(DISTANCES)
            if distance:
                distance = random_int(0, 255)
            tag = choice(TAGS)
            if tag:
                tag = random_int(0, 255)
            route_name = choice(ROUTE_NAMES)
            if route_name:
                route_name = random_string(minchar=4, maxchar=10)

            func = function('create',
                            ip_dest,
                            next_hop,
                            next_hop_ip=next_hop_ip,
                            distance=distance,
                            tag=tag,
                            route_name=route_name)

            # Build the expected string for comparison
            # A value of None will default to an empty string, and
            # add the tag or name keywords where appropriate
            cmd_next_hop_ip = cmd_distance = cmd_tag = cmd_route_name = ''
            if next_hop_ip is not None:
                cmd_next_hop_ip = " %s" % next_hop_ip
            if distance is not None:
                cmd_distance = " %d" % distance
            if tag is not None:
                cmd_tag = " tag %d" % tag
            if route_name is not None:
                cmd_route_name = " name %s" % route_name
            cmds = "ip route %s %s%s%s%s%s" % \
                   (ip_dest, next_hop, cmd_next_hop_ip, cmd_distance,
                    cmd_tag, cmd_route_name)

            self.eapi_positive_config_test(func, cmds)
Beispiel #45
0
    def try_clone(self):
        '''Make sure a clone matches'''
        self.tempdir = '/tmp/git-temp-' + testlib.random_string(8)

        giturl = 'file://' + gitrepo.repodir + '/.git'

        (rc,
         report) = testlib.cmd(["/usr/bin/git", 'clone', giturl, self.tempdir])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        (rc, report) = testlib.cmd([
            "/usr/bin/diff", '-q',
            os.path.join(gitrepo.repodir, gitrepo.testfile),
            os.path.join(self.tempdir, gitrepo.testfile)
        ])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        testlib.recursive_rm(self.tempdir)
        self.assertEquals(expected, rc, result + report)
Beispiel #46
0
    def test_logger(self):
        '''Test logger'''
        if self.lsb_release['Release'] >= 11.04:
            logfile = "/var/log/syslog"
        else:
            logfile = "/var/log/messages"

        unique_string = testlib.random_string(10)

        rc, report = testlib.cmd([
            'logger', '-t', 'test-util-linux',
            'Random String: ' + unique_string
        ])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        rc, report = testlib.cmd(['grep', unique_string, logfile])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)
    def test_create(self):
        # Test passing in a full set of parameters to 'create'
        # Some parameters may be not set: None
        for ip_dest in IP_DESTS:
            # Get the parameters for the call
            (next_hop, next_hop_ip) = choice(NEXT_HOPS)
            distance = choice(DISTANCES)
            if distance:
                distance = random_int(0, 255)
            tag = choice(TAGS)
            if tag:
                tag = random_int(0, 255)
            route_name = choice(ROUTE_NAMES)
            if route_name:
                route_name = random_string(minchar=4, maxchar=10)

            func = function('create', ip_dest, next_hop,
                            next_hop_ip=next_hop_ip,
                            distance=distance,
                            tag=tag,
                            route_name=route_name)

            # Build the expected string for comparison
            # A value of None will default to an empty string, and
            # add the tag or name keywords where appropriate
            cmd_next_hop_ip = cmd_distance = cmd_tag = cmd_route_name = ''
            if next_hop_ip is not None:
                cmd_next_hop_ip = " %s" % next_hop_ip
            if distance is not None:
                cmd_distance = " %d" % distance
            if tag is not None:
                cmd_tag = " tag %d" % tag
            if route_name is not None:
                cmd_route_name = " name %s" % route_name
            cmds = "ip route %s %s%s%s%s%s" % \
                   (ip_dest, next_hop, cmd_next_hop_ip, cmd_distance,
                    cmd_tag, cmd_route_name)

            self.eapi_positive_config_test(func, cmds)
    def setUp(self):
        '''Set up prior to each test_* function'''
        self.zope_instance = "/var/lib/zope3/instance/testinstance"
        self.zope_zdaemon = os.path.join(self.zope_instance, 'etc/zdaemon.conf')
        self.zope_logfile = os.path.join(self.zope_instance, 'log/z3.log')
        self.zope_transcriptfile = os.path.join(self.zope_instance, 'log/transcript.log')
        self.zope_port = '8080'
        self.zope_admin_user = "******"
        self.zope_admin_pass = testlib.random_string(12)
        self.daemon = testlib.TestDaemon("/etc/init.d/zope3")

        # Make sure we're stopped
        rc, result = self.daemon.stop()

        # Empty out the instance directory if it already exists
        if os.path.exists(self.zope_instance):
            testlib.recursive_rm(self.zope_instance)

        # Create the instance
        (rc, report) = testlib.cmd(['/usr/lib/zope3/bin/mkzopeinstance', '-d', self.zope_instance,
                                    '-u', self.zope_admin_user + ':' + self.zope_admin_pass,
                                    '--service-port=' + self.zope_port, '-m', 'Plain Text'])
        expected = 0
        result = 'Got exit code %d, expected %d\n' % (rc, expected)
        self.assertEquals(expected, rc, result + report)

        # Work around bug #356137 in jaunty
        if self.lsb_release['Release'] == 9.04:
            subprocess.call(['sed', '-i', 's/^define ZOPE_USER/%define ZOPE_USER/', self.zope_zdaemon])

        # Start the instance
        rc, result = self.daemon.start()

        report = 'Init script reported no instances found.\n'
        self.assertFalse('no instances found' in result, result + report)
        time.sleep(2)
Beispiel #49
0
 def test_config_with_single_command(self):
     command = random_string()
     self.node.run_commands = Mock(return_value=[{}, {}])
     result = self.node.config(command)
     self.assertEqual(result, [{}])
 def test_set_banner(self):
     banner_value = random_string() + "\n"
     func = function('set_banner', banner_type='motd',
                     value=banner_value)
     cmds = [dict(cmd='banner motd', input=banner_value)]
     self.eapi_positive_config_test(func, cmds)
Beispiel #51
0
 def test_set_mode_invalid_value_raises_value_error(self):
     value = random_string()
     func = function('set_mode', value)
     self.eapi_exception_config_test(func, ValueError)
Beispiel #52
0
 def test_set_lacp_mode_invalid_value(self):
     for dut in self.duts:
         mode = random_string()
         result = dut.api('interfaces').set_lacp_mode('Port-Channel1', mode)
         self.assertFalse(result)
Beispiel #53
0
 def test_set_mtu_invalid_value_raises_value_error(self):
     for intf in self.INTERFACES:
         for value in [67, 65536, random_string()]:
             func = function('set_mtu', intf, value)
             self.eapi_exception_config_test(func, ValueError)
Beispiel #54
0
 def test_set_portfast_invalid_intf_raises_value_error(self):
     intf = random_string()
     func = function('set_portfast', intf)
     self.eapi_exception_config_test(func, ValueError)
Beispiel #55
0
 def test_hosts_for_tag_returns_none(self):
     result = pyeapi.client.hosts_for_tag(random_string())
     self.assertIsNone(result)
Beispiel #56
0
 def test_config_with_multiple_commands(self):
     commands = [random_string(), random_string()]
     self.node.run_commands = Mock(return_value=[{}, {}, {}])
     result = self.node.config(commands)
     self.assertEqual(result, [{}, {}])