Exemplo n.º 1
0
 def pid_return_switch_monitor_file(self):
     t = test.Test()
     c = t.controller('c1')
     helpers.log("Verifing for monitor job")
     c_result = c.sudo('ps ax | grep tail | grep sudo')
     helpers.log("dumping sudo o/p:%s" % (c_result['content']))
     split = re.split('\s+', c_result['content'])
     # FIXME: Need to find another way to regex, to get pid rather splitting
     if split[9]:
         pid = split[9]
         return pid
     else:
         return 0
Exemplo n.º 2
0
    def _undefine_vm(self, **kwargs):
        kvm_handle = kwargs.get("kvm_handle", None)
        vm_name = kwargs.get("vm_name", None)

        if "undefined" in kvm_handle.bash("sudo virsh undefine %s" %
                                          vm_name)['content']:
            helpers.log("2. Successfully Deleted !")
            return True
        else:
            helpers.log(
                "Issue with Deleting VM using virsh \nPlease debug on KVM Host \n Exiting.."
            )
            return False
Exemplo n.º 3
0
    def start_monitor_switch_errors(self, file_name):
        t = test.Test()
        c1 = t.controller('c1')

        helpers.log("INFO: connecting to bash mode")
        helpers.log("INFO: Checking if file already exist in the controller")
        result = c1.sudo("ls -ltr | grep %s" % (file_name))
        helpers.log(" monitor file under C1: %s" % (result['content']))
        if re.findall(file_name, result['content']):
            helpers.log("File found under C1, deleting the file")
            c1.sudo('rm -rf c1_%s' % (file_name))
        helpers.log("Enabling the tail and redirecting to filename")
        c1.sudo('tail -f /var/log/switch/* | grep faultd | grep \"/bin/ofad\" > c1_%s &' % (file_name))
Exemplo n.º 4
0
    def virsh_cmd(self, node=None, virsh_cmd=None):
        '''

        '''
        t = test.Test()
        if node is None:
            helpers.log(
                "Please provide Host name of the Kvm Host to perform Virsh cmds..."
            )
            return True
        kvm_host = t.host(node)
        kvm_host.bash(virsh_cmd)
        helpers.log("Success executing virsh cmd..")
Exemplo n.º 5
0
    def _destroy_vm(self, **kwargs):
        kvm_handle = kwargs.get("kvm_handle", None)
        vm_name = kwargs.get("vm_name", None)

        if "destroyed" in kvm_handle.bash("sudo virsh destroy %s" %
                                          vm_name)['content']:
            helpers.log("Successfully powered down VM (destroyed)")
            return True
        else:
            helpers.log(
                "Issue with Shutting down VM using virsh \nPlease debug on KVM Host \n Exiting.."
            )
            return False
Exemplo n.º 6
0
 def _cp_qcow_to_images_folder(self, **kwargs):
     '''
         Copy qcow image to uniquely created vm_name to avoid overrides of qcow images
     '''
     kvm_handle = kwargs.get("kvm_handle", None)
     qcow_path = kwargs.get("qcow_path", None)
     vm_name = kwargs.get("vm_name", None)
     qcow_path = qcow_path.replace(" ", "\ ")
     kvm_handle.bash("sudo cp %s /var/lib/libvirt/images/%s.qcow2" %
                     (qcow_path, vm_name))
     kvm_qcow_path = "/var/lib/libvirt/images/%s.qcow2" % vm_name
     helpers.log("Success copying image !!")
     return kvm_qcow_path
Exemplo n.º 7
0
 def rest_get_active_end_point_count(self):
     ''' Function to get active end point count
     Input:
     Output: return end point count
     '''
     t = test.Test()
     c_master = t.controller('master')
     url = '/api/v1/data/controller/applications/bcf/info/summary/fabric'
     c_master.rest.get(url)
     data_master = c_master.rest.content()
     ep_count = data_master[0]["active-endpoint-count"]
     helpers.log("Total number of end points are %s" % (ep_count))
     return ep_count
Exemplo n.º 8
0
 def rest_delete_vip(self):
     
     t = test.Test()
     master = t.controller("master")
     url = "/api/v1/data/controller/os/config/global/virtual-ip-config"
     content = master.rest.delete(url)['content']
     
     if (content):
         helpers.log("result is: %s" % content)
         return False
     else:
         
         return True
Exemplo n.º 9
0
 def close(self, delete_session_cookie=True):
     if delete_session_cookie:
         try:
             self.rest.delete_session_cookie()
         except:
             helpers.log(
                 "Failed to delete REST session cookie for node '%s'. Ignore error."
                 % self.name())
     else:
         helpers.log(
             "Argument delete_session_cookie=%s. Don't delete session cookie."
             % delete_session_cookie)
     super(ControllerNode, self).close()
Exemplo n.º 10
0
 def ixia_verify_traffic_rate(self, tx_value, rx_value):
     tx = int(tx_value)
     rx = int(rx_value)
     if (rx >= (tx - 5)) and (rx <= (tx + 5)):
         helpers.log(
             "Pass:Traffic forwarded between 2 endpoints tx_rate:%d,rx_rate:%d"
             % (tx, rx))
         return True
     else:
         helpers.test_failure(
             "Fail:Traffic forward between 2 endpoints tx_rate:%d,rx_rate:%d"
             % (tx, rx))
         return False
Exemplo n.º 11
0
    def rest_add_fabric_role(self, switch, role):
        t = test.Test()
        c = t.controller()

        url = '%s/api/v1/data/controller/core/switch-config[name="%s"]' % (
            c.base_url, switch)
        c.rest.patch(url, {"fabric-role": role})

        if not c.rest.status_code_ok():
            helpers.log("Error: no matching commands")
            helpers.test_failure(c.rest.error())

        return c.rest.content()
Exemplo n.º 12
0
    def rest_verify_no_of_spine(self):
        t = test.Test()
        c = t.controller()
        url = '%s/api/v1/data/controller/core/switch' % (c.base_url)
        c.rest.get(url)
        data = c.rest.content()
        list_spine = []
        for i in range(0, len(data)):
            if data[i]["fabric-switch-info"]["fabric-role"] == "spine":
                list_spine.append(data[i]["fabric-switch-info"]["switch-name"])

        helpers.log("Total Spine in the topology: %d" % len(list_spine))
        return list_spine
Exemplo n.º 13
0
 def IxStartTrafficEthernet(handle, trafficHandle):
     helpers.log("### Starting Traffic")
     handle.execute('startAllProtocols')
     time.sleep(2)
     handle.execute('apply', handle.getRoot() + 'traffic')
     time.sleep(2)
     portStatistics = handle.getFilteredList(
         handle.getRoot() + 'statistics', 'view', '-caption',
         'Port Statistics')[0]
     time.sleep(2)
     handle.execute('startStatelessTraffic', trafficHandle)
     helpers.log("### Traffic Started")
     return portStatistics
Exemplo n.º 14
0
 def rest_show_switch(self):
     t = test.Test()
     c = t.controller('master')
     # url='http://%s:%s/api/v1/data/controller/core/switch' % (c.ip,c.http_port)
     url = '/api/v1/data/controller/core/switch'
     helpers.log("URL is %s  " % url)
     c.rest.get(url)
     content = c.rest.content()
     switchDict = {}
     for x in range(0, len(content)):
         switchDict[str(content[x]['inet-address']['ip'])] = str(
             content[x]['dpid'])
     return switchDict
Exemplo n.º 15
0
 def bash_restart_networking_service(self, node, timeout=None):
     """
     Restart networking service.
     """
     t = test.Test()
     h = t.controller(node)
     major_version = self.bash_lsb_release(node)
     helpers.log("Host %s is running Ubuntu major version %s" %
                 (node, major_version))
     if major_version == 12:
         h.sudo("/etc/init.d/networking restart", timeout=timeout)
     else:
         h.sudo("service networking restart", timeout=timeout)
Exemplo n.º 16
0
    def bash_ls(self, node, path):
        """
        Execute 'ls -l --time-style=+%Y-%m-%d <path>' on a device.

        Inputs:
        | node | reference to switch/controller/host as defined in .topo file |
        | path | directory to get listing for |

        Example:
        - bash ls    master    /home/admin
        - bash ls    h1        /etc/passwd

        Return Value:
        - Dictionary with file name as key. Value contains list of fields, where
            - fields[0] = file/dir
            - fields[1] = no of links
            - fields[2] = user
            - fields[3] = group
            - fields[4] = size
            - fields[5] = datetime
        """
        t = test.Test()
        n = t.node(node)
        content = n.bash('ls -l --time-style=+%%Y-%%m-%%d %s' %
                         path)['content']
        lines = helpers.strip_cli_output(content, to_list=True)

        # Output:
        # total 691740
        # -rw-r--r-- 1 root root 708335092 2014-03-03 13:08 controller-upgrade-bvs-2.0.5-SNAPSHOT.pkg
        # -rw-r--r-- 1 bsn  bsn          0 2014-03-12 10:05 blah blah.txt

        # Strip first line ('total <nnnnn>')
        lines = lines[1:]
        # helpers.log("lines: %s" % helpers.prettify(lines))

        files = {}

        for line in lines:
            fields = line.split()
            helpers.log("fields: %s" % fields)
            # fields[6]+ contains filename (may have spaces in name)
            filename = ' '.join(fields[6:])

            # If file is a symlink, remove the symlink (leave just the name)
            # E.g., 'blkid.tab -> /dev/.blkid.tab'
            filename = re.sub('-> .*$', '', filename)
            files[filename] = fields[0:6]

        helpers.log("files:\n%s" % helpers.prettify(files))
        return files
Exemplo n.º 17
0
 def verify_switch_ip_dns(self, ip_address, subnet, gateway, dns_server,
                          dns_domain):
     '''Verify Switch Correctly reports configured IP Address and DNS
     
         Input: 
             ip_address:    Switch IP address in 1.2.3.4 format
             subnet:        Switch subnet in /18 /24 format
             gateway        IP address of default gateway
             dns_server     dns-server IP address in 1.2.3.4 format
             dns-domain    dns-server IP address in bigswitch.com format
     '''
     try:
         conn = SSH2()
         conn.connect(ip_address)
         conn.login(Account("admin", "adminadmin"))
         conn.execute('enable')
         conn.execute('show running-config interface')
         run_config = conn.response
         helpers.log("Running Config O/P: \n %s" % (run_config))
         pass_count = 0
         input1 = "interface ma1 ip-address " + str(ip_address) + "/" + str(
             subnet)
         if input1 in run_config:
             pass_count = pass_count + 1
         input2 = "ip default-gateway " + str(gateway)
         if input2 in run_config:
             pass_count = pass_count + 1
         input3 = "dns-domain " + str(dns_domain)
         if input3 in run_config:
             pass_count = pass_count + 1
         input4 = "dns-server " + str(dns_server)
         if input4 in run_config:
             pass_count = pass_count + 1
         conn.execute('show interface ma1 detail')
         show_command = conn.response
         helpers.log("Show Command O/P: \n %s" % (show_command))
         if "ma1 is up" in show_command:
             pass_count = pass_count + 1
         input5 = str(ip_address) + "/" + str(subnet)
         if input5 in show_command:
             pass_count = pass_count + 1
         if "MTU 1500 bytes, Speed 1000 Mbps" in show_command:
             pass_count = pass_count + 1
         if pass_count == 7:
             return True
         else:
             return False
     except:
         helpers.test_failure(
             "Could not execute command. Please check log for errors")
         return False
Exemplo n.º 18
0
 def rest_verify_fabric_switch_all(self):
     t = test.Test()
     c = t.controller()
     url = '%s/api/v1/data/controller/core/switch' % (c.base_url)       
     c.rest.get(url)
     data = c.rest.content()
     for i in range (0,len(data)):
         if data[i]["fabric-switch-info"]["suspended"] is True and (data[i]["fabric-switch-info"]["fabric-role"] == "leaf" or data[i]["fabric-switch-info"]["fabric-role"] == "spine"):
             helpers.test_failure("Fabric manager status is incorrect")
         elif data[i]["fabric-switch-info"]["suspended"] is False and (data[i]["fabric-switch-info"]["fabric-role"] == "virtual"):
             helpers.test_failure("Fabric manager status is incorrect") 
     helpers.log("Fabric manager status is correct")     
                                                                              
     return True
Exemplo n.º 19
0
 def rest_verify_fabric_interface(self, switch, intf):
     ''' 
     Function to verify the specific fabric interface status 
     Input:  Rest Output from the function (show_fabric_interface())
     Output" validation of the fabric interface status
     '''
     t = test.Test()
     c = t.controller()
     url = '%s/api/v1/data/controller/core/switch[name="%s"]/interface[name="%s"]' % (
         c.base_url, switch, intf)
     c.rest.get(url)
     data = c.rest.content()
     helpers.log("Data %s" % data)
     if len(data) != 0:
         if data[0]["state"] == "down" and data[0]["type"] == "unknown":
             helpers.log(
                 "Interface is connected to spine or Physical Interface status is down for the leaf switch"
             )
         elif data[0]["state"] == "up" and data[0]["type"] == "edge":
             helpers.log(
                 "Inteface is connected to leaf and it is a edge port")
         elif data[0]["state"] == "up" and data[0]["type"] == "leaf" or data[
                 0]["state"] == "up" and data[0]["type"] == "spine":
             helpers.log("Interface is fabric interface")
         else:
             helpers.test_failure(
                 "Interface status is not known to the fabric system , Please check the logs"
             )
     else:
         helpers.test_failure("Given fabric interface is not valid")
Exemplo n.º 20
0
    def Host_powercycle(self, host):
        ''' power cycle a host and wait for it to come back.
        '''
        t = test.Test()
        node = t.node(host)
        ipAddr = node.ip()
        t.power_cycle(host, minutes=0)
        helpers.log("*****system went through power cycle********")

        helpers.sleep(120)
        count = 0
        while (True):
            loss = helpers.ping(ipAddr)
            helpers.log("loss is: %s" % loss)
            if (loss != 0):
                if (count > 10):
                    helpers.warn(
                        "Cannot connect to the IP Address: %s - Tried for 5 Minutes"
                        % ipAddr)
                    return False
                helpers.sleep(60)
                count += 1
                helpers.log(
                    "Trying to connect to the IP Address: %s - Try %s" %
                    (ipAddr, count))
            else:
                helpers.log(
                    "USR INFO:  system just came alive. Waiting for it to become fully functional"
                )
                helpers.sleep(30)
                break

        return True
Exemplo n.º 21
0
 def bash_get_interface_ipv4(self, node, intf):
     t = test.Test()
     n = t.node(node)
     output = n.sudo("ifconfig %s | grep --color=never -i 'inet addr'" %
                     intf)['content']
     return_stat = n.sudo('echo $?')['content']
     return_stat = helpers.strip_cli_output(return_stat)
     helpers.log("output: %s" % output)
     helpers.log("return_stat: %s" % return_stat)
     if int(return_stat) == 1:
         return ''
     else:
         result = re.search('inet addr:(.*)\sBcast', output)
         return result.group(1)
Exemplo n.º 22
0
 def rest_verify_fabric_switch(self, dpid):
     # Function verify fabric switch status for default as well after fabric role configuration
     t = test.Test()
     c = t.controller()
     url = '%s/api/v1/data/controller/core/switch[dpid="%s"]' % (c.base_url, dpid)       
     c.rest.get(url)
     data = c.rest.content()
     if data[0]["dpid"] == dpid:
         if data[0]["connected"]:
             if data[0]["fabric-switch-info"]["fabric-role"] != "virtual":
                 if data[0]["fabric-switch-info"]["fabric-role"] == "spine" and data[0]["fabric-switch-info"]["suspended"] == False:
                     helpers.log("Pass: Fabric switch connection status for spine is correct")
                     return True
                 elif data[0]["fabric-switch-info"]["fabric-role"] == "leaf" and data[0]["fabric-switch-info"]["suspended"] == False and data[0]["fabric-switch-info"]["leaf-group"] != '':
                     if data[0]["dpid"] == dpid and data[0]["fabric-switch-info"]["lacp-port-offset"] == 0:
                         helpers.log("Pass: Fabric switch connection status for %s dual leaf is correct" % str(data[0]["fabric-switch-info"]["switch-name"]))
                         return True
                     elif data[0]["dpid"] == dpid and data[0]["fabric-switch-info"]["lacp-port-offset"] == 100:
                         helpers.log("Pass: Fabric switch connection status for %s dual leaf is correct" % str(data[0]["fabric-switch-info"]["switch-name"]))
                         return True
             elif data[0]["fabric-switch-info"]["suspended"] == True:
                     helpers.log("Default fabric role is virtual for not added fabric switches")
                     return True
             else: 
                     helpers.test_failure("Fabric role is virual but suspended = False ") 
                     return False                        
         elif data[0]["fabric-switch-info"]["suspended"] == False or data[0]["fabric-switch-info"]["suspended"] == True:
             helpers.test_failure("Fail: Switch is not connected , Fabric switch status still exists")
             return False    
     else :
         return False
Exemplo n.º 23
0
 def bash_check_service_status(self, node, processname):
     t = test.Test()
     n = t.node(node)
     output = n.bash("service %s status" % processname)['content']
     helpers.log("output: %s" % output)
     match = re.search(r'unrecognized service', output, re.S | re.I)
     if match:
         return 'unrecognized service'
     match = re.search(r'is not running', output, re.S | re.I)
     if match:
         return 'is not running'
     match = re.search(r'(start|running)', output, re.S | re.I)
     if match:
         return 'is started'
Exemplo n.º 24
0
    def rest_bigtap_delete_interface_role(self,
                                          intf_name,
                                          intf_type,
                                          intf_nickname,
                                          switch_alias=None,
                                          sw_dpid=None):
        '''Delete filter/service/delivery interface from switch configuration. Similar to executing the CLI command 'no bigtap role filter interface-name F1'

            Input:
                `switch_dpid` : DPID of the switch
                `intf_name`    : Interface Name viz. etherenet1, ethernet2 etc.
                `intf_type`    : Interface Type viz. filter, delivery, service
                `intf_nickname`    : Nickname for the interface for eg. F1, D1, S1 etc.

            Returns: True if delete is successful, false otherwise
        '''
        try:
            t = test.Test()
        except:
            return False
        else:
            c = t.controller('master')
            try:
                if (switch_alias is None and sw_dpid is not None):
                    switch_dpid = sw_dpid
                elif (switch_alias is None and sw_dpid is None):
                    helpers.log(
                        'Either Switch DPID or Switch Alias has to be provided'
                    )
                    return False
                elif (switch_alias is not None and sw_dpid is None):
                    switch_dpid = self.rest_get_switch_dpid(switch_alias)
                else:
                    switch_dpid = sw_dpid

                url = '/api/v1/data/controller/applications/bigtap/interface-config[interface="%s"][switch="%s"]' % (
                    str(intf_name), str(switch_dpid))
                c.rest.delete(url, {
                    'role': str(intf_type),
                    "name": str(intf_nickname)
                })
            except:
                helpers.test_failure(c.rest.error())
                return False
            else:
                if not c.rest.status_code_ok():
                    helpers.test_failure(c.rest.error())
                    return False
                else:
                    return True
Exemplo n.º 25
0
    def cli_return_ofaux_connection_from_alias(self, controller, switch_alias):
        '''
                Objective:
                - Get the switch ofaux connections from controller using switch_alias

                Input:
                | controller_ip | IP Address of Controller |
                | switch_alias | Reference to switch alias as user input |
                | controller_role | Role of controller (Active/Backup) |

                Return Value:
                - True on verification success
                - False on verification failure
            '''
        t = test.Test()
        c = t.controller(controller)
        try:
            url_to_get = '/api/v1/data/controller/core/switch[name="%s"]?select=connection' % str(
                switch_alias)
            c.rest.get(url_to_get)
        except:
            helpers.log("Could not execute GET on URL")
            return False
        else:
            data1 = c.rest.content()
            numofaux = len(data1[0]["connection"])
            helpers.log("Total number of aux channel is %d" % numofaux)
            if numofaux == 4:
                helpers.log("Total number of aux channel is correct %d" %
                            numofaux)
                return True
            else:
                helpers.log("Total number of aux channel is not correct %d" %
                            numofaux)
                return False
Exemplo n.º 26
0
 def get_support_bundle_name(self, node_name='master'):
     '''
     Get The Name of the Support Bundle that is first available on the controller
     '''
     t = test.Test()
     node = t.controller(node_name)
     data = self.get_support_bundles(node_name)
     if len(data) == 0:
         helpers.log("No Support Bundles Found on Controller %s" % node)
         return False
     else:
         for i in range(0, len(data)):
             helpers.log("Support Bundle Name: %s" % data[i]['name'])
             return data[i]['name']
Exemplo n.º 27
0
 def bash_get_intf_mac(self, node, intf):
     '''
         return mac address of a host interface
     '''
     t = test.Test()
     n = t.node(node)
     output = n.sudo("ifconfig %s | grep --color=never HWaddr" %
                     (intf))['content']
     return_stat = n.sudo('echo $?')['content']
     return_stat = helpers.strip_cli_output(return_stat)
     helpers.log("return_stat: %s" % return_stat)
     if int(return_stat) == 1:
         #            helpers.log("I am here")
         return ''
     else:
         #            helpers.log("I am there")
         #            helpers.log("output: %s" % output)
         output = helpers.strip_cli_output(output)
         result = re.search('HWaddr (.*)', output)
         mac_addr = result.group(1)
         helpers.log("output: %s" % output)
         helpers.log("result: %s" % result)
         # mac = mac_addr.replace("\r", "")
         mac = mac_addr.strip(' \t\n\r')
         helpers.log("mac_addr: %s" % mac_addr)
         return mac
Exemplo n.º 28
0
 def get_support_bundle_fs_path(self, node_name='master'):
     '''
     Get the absolute path of the first available support bundle from controller
     '''
     t = test.Test()
     node = t.controller(node_name)
     data = self.get_support_bundles(node_name)
     if len(data) == 0:
         helpers.log("No Support Bundles Found on Controller %s" % node)
         return False
     else:
         for i in range(0, len(data)):
             helpers.log("fs-path: %s" % data[i]['fs-path'])
             return data[i]['fs-path']
Exemplo n.º 29
0
 def get_node_mac_address(self, node_name="master"):
     '''
         Get the HW mac address of the give Node from ifconfig output
     '''
     t = test.Test()
     node = t.controller(node_name)
     mac_output = node.bash(
         "ifconfig eth0 | grep HWaddr | awk '{print $5}'")
     helpers.log(mac_output['content'])
     mac_output_lines = mac_output['content'].split('\n')
     for line in mac_output_lines:
         match = re.match(r'.*(([0-9a-f]{2}[:-]){5}([0-9a-f]{2})).*',
                          str(line))
         if match:
             return match.group(1)
Exemplo n.º 30
0
 def IxStartTrafficIP(handle, trafficHandle):
     helpers.log("### Starting Traffic")
     handle.setAttribute(handle.getRoot() + '/traffic',
                         '-refreshLearnedInfoBeforeApply', True)
     handle.commit()
     handle.execute('startAllProtocols')
     time.sleep(20)
     handle.execute('apply', handle.getRoot() + 'traffic')
     time.sleep(2)
     portStatistics = handle.getFilteredList(
         handle.getRoot() + 'statistics', 'view', '-caption',
         'Port Statistics')[0]
     handle.execute('start', handle.getRoot() + 'traffic')
     helpers.log("### Traffic Started")
     return portStatistics