Exemplo n.º 1
0
def scenario_test():
    # navi_menu = SCEN_TEST_MENU
    os.system('clear')
    # file search
    title_print(' # scenario test')
    scen_list = scenario_file_search()
    scen_list.sort()
    for i in range(len(scen_list)):
        Reporter.PRINTB("| %2d. %s|", i+1, (scen_list[i]).ljust(menu_string2_len))
    Reporter.PRINTB("|%s|", ('  0. return to main menu').ljust(menu_string_len))
    Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))

    while 1:
        sel_scen = input(RED + 'select scenario : '+ENDC)
        if len(scen_list) < sel_scen:
            Reporter.PRINTR(" Invalid value !!")
            continue
        elif 0 is sel_scen:
            break
        else:
            if 'create_' in scen_list[sel_scen-1]:
                create_start_scenario(scen_list[sel_scen-1])
            elif 'delete_' in scen_list[sel_scen-1]:
                delete_start_scenario(scen_list[sel_scen-1])
            break
Exemplo n.º 2
0
    def ssh_connect(self, host, user, port, password):
        try:
            ssh_newkey = 'Are you sure you want to continue connecting'
            if '' is port:
                connStr = 'ssh ' + user + '@' + host
            else:
                connStr = 'ssh ' + '-p ' + port + ' ' + user + '@' + host
            # print connStr
            conn = pexpect.spawn(connStr)
            ret = conn.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'],
                              timeout=3)

            if ret == 0:
                Reporter.REPORT_MSG(
                    '   >> [%s] Error Connection to SSH Server', host)
                return False
            if ret == 1:
                conn.sendline('yes')
                ret = conn.expect([pexpect.TIMEOUT, '[P|p]assword'], timeout=3)
            if ret == 0:
                Reporter.REPORT_MSG(
                    '   >> [%s] Error Connection to SSH Server', host)
                return False

            conn.sendline(password)
            conn.expect(PROMPT, timeout=5)

        except Exception, e:
            Reporter.REPORT_MSG('   >> [%s] Error Connection to SSH Server',
                                host)
            # print e
            return False
Exemplo n.º 3
0
    def port_info(self, conn_info, dev_id):
        try:
            conn = self.onos_create_session(conn_info)
            url = 'http://' + conn_info[
                'host'] + ':8181/onos/v1/devices/' + dev_id + '/ports'
            header = {'Accept': 'application/json'}
            # print json.dumps(conn.get(url, headers=header).json(),indent=4, separators=('',':'))
            ret = json.dumps(
                conn.get(url,
                         headers=header,
                         timeout=self._config.get_onos_timeout()).json(),
                ensure_ascii=False,
                sort_keys=False).encode('utf-8')

            result = dict()
            for x in json.loads(ret)['ports']:
                result[x['annotations']['portName']] = x['isEnabled']

            if not len(result):
                Reporter.REPORT_MSG(
                    '   >> Device[%s] Get port fail from [%s] ', dev_id,
                    conn_info['host'])
                return

            return result

        except:
            Reporter.exception_err_write()
            return
Exemplo n.º 4
0
def config_subnet(type):
    value = []
    value_list=[]
    title_print(' # ' + type + ' subnet')
    # network
    while 1:
        if 'create' in type:
            net_list, sel, sel_state = display_config_item('network')
            if False is sel_state: value = [] ; continue
            if 0 is sel: value = [] ; break
            value.append(net_list[sel-1])
            Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))

        ## subnet
        sub_list, sel, sel_state = display_config_item('subnet')
        if False is sel_state: value = [] ; continue
        if 0 is sel: value = [] ; break
        value.append(sub_list[sel-1])

        if 'create' in type:
            val_str = ', '.join(value)
        else:
            val_str = ''.join(value)
        value_list.append(val_str)

        value=[]
        choice = select_yesno_menu('Do you want to continue to ' + type + ' subnet?(y/n) : ')
        if 'n' in choice: break
        Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))

    if len(value_list) > 0:
        set_list = list(set(value_list))
        set_list.sort()
        save_scenario('subnet', set_list, type)
Exemplo n.º 5
0
def config_router_interface(type):
    value = []
    value_list=[]
    if 'create' in type:
        title_print(' # add router-interface')
    else:
        title_print(' # del router-interface')

    while 1:
        # router
        router_list, sel, sel_state = display_config_item('router')
        if False is sel_state: value = [] ; continue
        if 0 is sel: value = [] ; break
        value.append(router_list[sel-1])

        # subnet
        Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))
        sub_list, sel, sel_state = display_config_item('subnet')
        if False is sel_state: value = [] ; continue
        if 0 is sel: value = [] ; break
        value.append(sub_list[sel-1])

        val_str = ', '.join(value)
        value_list.append(val_str)
        value=[]
        choice = select_yesno_menu('Do you want to continue to ' + type + ' router-interface?(y/n) : ')
        if 'n' in choice: break
        Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))

    if len(value_list) > 0:
        set_list = list(set(value_list))
        set_list.sort()
        save_scenario('router-interface', set_list, type)
Exemplo n.º 6
0
    def ssh_connect(self, host, user, port, password):
        try:
            ssh_newkey = 'want to continue connecting'
            if '' is port:
                connStr = 'ssh ' + user + '@' + host
            else:
                connStr = 'ssh ' + '-p ' + port + ' ' + user + '@' + host
            Reporter.REPORT_MSG('   >> connection : %s', connStr)
            conn = pexpect.spawn(connStr)
            ret = conn.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'],
                              timeout=self.conn_timeout)
            if ret == 0:
                Reporter.REPORT_MSG(
                    '   >> [%s] Error Connection to SSH Servcer(%d)', host,
                    ret)
                self.ssh_disconnect(conn)
                return False
            if ret == 1:
                # Reporter.REPORT_MSG('   >> [%s] wait %s ', host, ssh_newkey)
                conn.sendline('yes')
                ret = conn.expect([pexpect.TIMEOUT, '[P|p]assword'],
                                  timeout=self.conn_timeout)

            conn.sendline(password)
            conn.expect(PROMPT, timeout=self.conn_timeout)

        except Exception, e:
            Reporter.REPORT_MSG(
                '   >> [%s] Error Connection to SSH Servcer (timeout except)',
                host)
            self.ssh_disconnect(conn)
            return False
Exemplo n.º 7
0
    def add_securitygroup_rule(self, sg_uuid, rule_opt_list):
        rule_rst = []
        for rule in rule_opt_list:
            rule_conf = dict(self.rule_conf)[rule.strip()]
            if not rule_conf:
                Reporter.REPORT_MSG("   >> Not Exist Rule ---> %s", rule)
                return
            rule_body = ast.literal_eval(rule_conf)
            rule_body['security_group_id'] = sg_uuid
            rule_body = {'security_group_rule': rule_body}

            try:
                remote_group_name = rule_body['security_group_rule'][
                    'remote_group_id']
                if remote_group_name:
                    remote_group_id = self.get_sg_uuid_by_name(
                        remote_group_name)
                    rule_body['security_group_rule'][
                        'remote_group_id'] = remote_group_id
            except:
                Reporter.REPORT_MSG(
                    "   >> no remote security group in the rule -> OK")

            rule_rst.append(self.neutron.create_security_group_rule(rule_body))
        Reporter.REPORT_MSG("   >> Security Group ---> %s", rule_rst)
        return rule_rst
Exemplo n.º 8
0
    def openstack_get_service(self, report_flag=None):
        if report_flag is None:
            Reporter.unit_test_start(True)
        try:
            keystone = kclient.Client(auth_url=self.auth['auth_url'],
                                      username=self.auth['username'],
                                      password=self.auth['api_key'],
                                      tenant_name=self.auth['project_id'])
            service_list = [{
                a.name: a.enabled
            } for a in keystone.services.list()]

            for i in range(len(service_list)):
                if service_list[i].values()[0] is False:
                    Reporter.REPORT_MSG(
                        "   >> OpenStack Service status NOK ---> %s",
                        service_list[i])
                    if report_flag is None:
                        Reporter.unit_test_stop('nok')
                    return False

            Reporter.REPORT_MSG("   >> OpenStack Service status OK ---> %s",
                                service_list)

            if report_flag is None:
                Reporter.unit_test_stop('ok')

            return True

        except:
            if report_flag is None:
                Reporter.exception_err_write()
            return False
Exemplo n.º 9
0
    def create_subnet(self, network_opt, subnet_opt):
        Reporter.unit_test_start(True, network_opt, subnet_opt)
        try:
            # if not subnet_body:
            #     Reporter.REPORT_MSG("   >> Not Exist Subnet in config --->")
            #     return
            network_uuid = self.get_network_uuid(network_opt)
            if not network_uuid:
                Reporter.unit_test_stop('nok')
                return

            if self.get_subnet_uuid(subnet_opt):
                Reporter.unit_test_stop('skip')
                return

            subnet_cfg_body = dict(self.subnet_conf)[subnet_opt]
            subnet_body = ast.literal_eval("{'subnets': [" + subnet_cfg_body + "]}")

            subnet_body['subnets'][0]['network_id'] = network_uuid
            subnet_rst = self.neutron.create_subnet(body=subnet_body)
            Reporter.REPORT_MSG("   >> Create Subnet --->%s, %s, %s",
                                network_opt, subnet_opt, dict(subnet_rst).values())
            Reporter.unit_test_stop('ok')
            return subnet_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 10
0
    def create_securitygroup(self, sg_opt, rule_opt_list):
        Reporter.unit_test_start(True, sg_opt, rule_opt_list)
        try:
            sg_uuid = self.get_sg_uuid_by_name(self.get_sg_name(sg_opt))
            if sg_uuid:
                Reporter.REPORT_MSG("   >> Already Exist Security Group ---> %s: %s",
                                    sg_opt, sg_uuid)
                Reporter.unit_test_stop('skip')
                return

            sg_body = dict(self.sg_conf)[sg_opt]
            sg_body = ast.literal_eval("{'security_group': " + sg_body + "}")

            # Create New Security Group
            sg_rst = self.neutron.create_security_group(sg_body)
            Reporter.REPORT_MSG("   >> Create Security Group ---> %s", sg_rst)

            # Make Rule to Security Group
            rule_rst = self.add_securitygroup_rule(sg_rst['security_group']['id'],
                                                   rule_opt_list.split(','))
            if not rule_rst:
                Reporter.REPORT_MSG("   >> Security Group Rule Create Error ")
                Reporter.REPORT_MSG("   >> Delete Security Group")
                self.neutron.delete_security_group(sg_rst['security_group']['id'])
                Reporter.unit_test_stop('nok')
                return

            Reporter.REPORT_MSG("   >> Create Security Group Rule ---> %s", rule_rst)
            Reporter.unit_test_stop('ok')
            return rule_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 11
0
    def delete_securitygroup(self, sg_opt):
        Reporter.unit_test_start(True, sg_opt)
        sg_uuid = ''
        sg_rst = []
        try:
            sg_uuid = self.get_sg_uuid_by_name(self.get_sg_name(sg_opt))
            if not sg_uuid:
                Reporter.unit_test_stop('skip')
                return

            sg_rst.append(self.neutron.delete_security_group(sg_uuid))
            Reporter.REPORT_MSG("   >> Delete Security Group Succ ---> %s, %s",
                                sg_opt, sg_rst)
            Reporter.unit_test_stop('ok')
            return sg_rst
        except client.exceptions.Conflict, err:
            Reporter.REPORT_MSG("   >> Conflict error, after sleep 3 seconds, delete retry")
            time.sleep(3)
            try:
                self.neutron.delete_security_group(sg_uuid)
            except:
                Reporter.exception_err_write()
            Reporter.REPORT_MSG("   >> Delete Security Group Succ ---> %s", sg_opt)
            Reporter.unit_test_stop('ok')
            return
Exemplo n.º 12
0
    def get_subnet_lists(self):
        subnet_rst = self.neutron.list_subnets()
        if not subnet_rst:
            Reporter.REPORT_MSG("   >> Not Exist Subnet --->")
            return

        Reporter.REPORT_MSG("   Subnet All List ---> %s ", dict(subnet_rst).values())
        return subnet_rst
Exemplo n.º 13
0
def title_print(menu='None'):
    Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))
    print BLUE + '|' + BG_BLUEW + \
          ("{0:^"+str(menu_string_len)+"}").format("SONA-TOOL") + BLUE + '|'+ENDC

    Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))
    if 'None' not in menu:
        print BLUE + '|' + BG_PINKW + \
                      ("{0:<"+str(menu_string_len)+"}").format(menu)  + BLUE + '|'+ENDC
        Reporter.PRINTB("|%s|", ('-'*menu_string_len).ljust(menu_string_len))
Exemplo n.º 14
0
    def openstack_get_token(self, report_flag=None):
        if report_flag is None:
            Reporter.unit_test_start(True)

        try:
            auth = v2.Password(username=self.auth['username'],
                               password=self.auth['password'],
                               tenant_name=self.auth['tenant_id'],
                               auth_url=self.auth['auth_url'])
            sess = session.Session(auth=auth, timeout=5)

            token = sess.get_token()
            if not token:
                Reporter.REPORT_MSG(
                    "   >> OpentStack Authentication NOK ---> get token fail")
                if report_flag is None:
                    Reporter.unit_test_stop('nok')
                return False
            else:
                Reporter.REPORT_MSG(
                    "   >> OpenStack Authentication OK ---> user: %s, token: %s",
                    self.auth['username'], token)

            if report_flag is None:
                Reporter.unit_test_stop('ok')
            return True

        except exceptions.AuthorizationFailure, err:
            Reporter.REPORT_MSG("   >> OpentStack Authentication Fail ---> %s",
                                err)
            return False
Exemplo n.º 15
0
 def get_admin_auth(self, user):
     try:
         auth = v2.Password(username=user['username'],
                            password=user['api_key'],
                            tenant_name=user['project_id'],
                            auth_url=user['auth_url'])
         sess = session.Session(auth=auth, timeout=5)
         return client.Client(session=sess)
         # return sess
     except:
         Reporter.exception_err_write()
Exemplo n.º 16
0
def set_router_state(type):
    Reporter.initial_test_count()
    title_print(' # router ' + type)
    # Router
    while 1:
        router_list, sel, sel_state = display_config_item('router')
        if False is sel_state: continue
        if 0 is sel: break
        test.network.set_router_up(router_list[sel-1])
        test.reporter.test_summary()
        report_log_viewer()
        break
Exemplo n.º 17
0
 def get_network_uuid(self, network_opt):
     network_name = self.get_network_name(network_opt)
     if not network_name:
         return
     network_rst = self.neutron.list_networks(name=network_name)
     if dict(network_rst)['networks']:
         Reporter.REPORT_MSG("   >> Exist Network on OpenStack ---> %s", network_rst)
         network_uuid = dict(network_rst)['networks'][0]['id']
         return network_uuid
     else:
         Reporter.REPORT_MSG("   >> Not Exist Network on OpenStack ---> %s", network_opt)
         return
Exemplo n.º 18
0
 def get_subnet_uuid(self, subnet_opt):
     subnet_name = self.get_subnet_name(subnet_opt)
     if not subnet_name:
         return
     subnet_rst = self.neutron.list_subnets(name=subnet_name)
     if dict(subnet_rst)['subnets']:
         Reporter.REPORT_MSG("   >> Exist Subnet on OpenStack ---> response: %s", subnet_rst)
         subnet_uuid = dict(subnet_rst)['subnets'][0]['id']
         return subnet_uuid
     else:
         Reporter.REPORT_MSG("   >> Not Exist Subnet on OpenStack --->")
         return
Exemplo n.º 19
0
 def create_user(self):
     Reporter.unit_test_start(True)
     tenant_id = ''
     user_id = ''
     try:
         tenant_id = self.admin_user.tenants.create(tenant_name=self.identity['tenant_id'],
                                                  description="SONA Test Temporary Tenant",
                                                  enabled=True).id
     except exceptions.Conflict, err:
         tenant_list = self.admin_user.tenants.list()
         tenant_id = [x.id for x in tenant_list if x.name == self.identity['tenant_id']][0]
         Reporter.REPORT_MSG("   >> Already exist tenant(%s) > tenant_id: %s",
                             self.identity['tenant_id'], tenant_id)
Exemplo n.º 20
0
def delete_start_scenario(scen_name):
    Reporter.initial_test_count()
    ret = display_scenario(scen_name)
    if False is ret:
        return False

    # global test
    scen_file = SCENARIO_PATH+scen_name+'.ini'
    scen_ini = ConfigParser()
    scen_ini.read(scen_file)

    # Instance
    item = scen_ini._sections['instance']
    for i in range(len(item)):
        if i is not 0:
            test.instance.delete_instance((item.values()[i]).split(', ')[0])

    # Floating IP
    test.instance.delete_floatingip_all()

    # Security Group
    item = scen_ini._sections['security_group']
    for i in range(len(item)):
        if i is not 0:
            test.network.delete_seuritygroup((item.values()[i]).split(', ')[0])

    # Router interface
    item = scen_ini._sections['router-interface']
    for i in range(len(item)):
        if i is not 0:
            test.network.remove_router_interface((item.values()[i]).split(', ')[0],
                                       (item.values()[i]).split(', ')[1])
    # Router
    item = scen_ini._sections['router']
    for i in range(len(item)):
        if i is not 0:
            test.network.delete_router((item.values()[i]).split(', ')[0])

    # SubNet
    item = scen_ini._sections['subnet']
    for i in range(len(item)):
        if i is not 0:
            test.network.delete_subnet((item.values()[i]).split(', ')[0])
    # Network
    item = scen_ini._sections['network']
    for i in range(len(item)):
        if i is not 0:
            test.network.delete_network(item.values()[i])

    test.reporter.test_summary()
    report_log_viewer()
Exemplo n.º 21
0
 def delete_floatingip_all(self):
     Reporter.unit_test_start(True)
     try:
         floatingip_list = self.get_floatingip_list()
         if not floatingip_list:
             Reporter.REPORT_MSG("   >> Not exist Floating IP --->")
             Reporter.unit_test_stop('skip')
             return
         for f in floatingip_list:
             self.nova.floating_ips.delete(f)
         Reporter.REPORT_MSG("   >> All Floating IP Delete Succ --->")
         Reporter.unit_test_stop('ok')
         return
     except:
         Reporter.exception_err_write()
Exemplo n.º 22
0
    def get_instance(self, instance_opt):
        config_value = self.find_instance(instance_opt)
        if not config_value:
            return

        instance_rst = self.nova.servers.list(
            search_opts={'name': config_value['name']})
        if not instance_rst:
            Reporter.REPORT_MSG("   >> Not exist openstack ---> %s",
                                instance_opt)
            return

        Reporter.REPORT_MSG("   >> Get Instance  ---> %s %s", instance_opt,
                            instance_rst)
        return instance_rst
Exemplo n.º 23
0
 def delete_router(self, router_opt):
     Reporter.unit_test_start(True, router_opt)
     try:
         router_uuid = self.get_router_uuid(router_opt)
         if not router_uuid:
             Reporter.unit_test_stop('skip')
             return
         router_rst = self.neutron.delete_router(router_uuid)
         Reporter.REPORT_MSG("   >> Delete Router ---> %s", router_rst)
         Reporter.unit_test_stop('ok')
     except:
         Reporter.exception_err_write()
Exemplo n.º 24
0
def set_port_state(type):
    Reporter.initial_test_count()
    title_print(' # port ' + type)
    while 1:
        # Instance
        inst_list, inst_sel, inst_sel_state = display_config_item('instance')
        if False is inst_sel_state: continue
        if 0 is inst_sel: break
        # Network
        net_list, net_sel, net_sel_state = display_config_item('network')
        if False is net_sel_state: continue
        if 0 is net_sel: break
        test.network.set_port_up(inst_list[inst_sel-1], net_list[net_sel-1])
        test.reporter.test_summary()
        report_log_viewer()
        break
Exemplo n.º 25
0
 def get_router_name(self, router_opt):
     router_conf = dict(self.router_conf)[router_opt]
     if not router_conf:
         Reporter.REPORT_MSG("   >> Not Exist config file ---> %s", router_opt)
         return
     router_name = ast.literal_eval(router_conf)['name']
     return router_name
Exemplo n.º 26
0
 def get_network_name(self, network_opt):
     network_body = dict(self.network_conf)[network_opt]
     if not network_body:
         Reporter.REPORT_MSG("   >> Not Exist Network in Config ---> %s", network_opt)
         return
     network_name = ast.literal_eval(network_body)['name']
     return network_name
Exemplo n.º 27
0
    def get_network(self, network_opt):
        Reporter.unit_test_start(True, network_opt)
        try:
            network_name = self.get_network_name(network_opt)
            if not network_name:
                return

            network_rst = self.neutron.list_networks(name=network_name)
            if not dict(network_rst)['networks']:
                Reporter.REPORT_MSG("   >> Not Exist Network in OpenStack")
                return

            Reporter.REPORT_MSG("   >> Network List ---> %s %s", network_opt, dict(network_rst).values())
            return network_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 28
0
    def delete_router(self, router_opt):
        Reporter.unit_test_start(True, router_opt)
        try:
            router_uuid = self.get_router_uuid(router_opt)
            if not router_uuid:
                Reporter.unit_test_stop('skip')
                return
            elif router_uuid == 'fail':
                Reporter.unit_test_stop('nok')
                return

            router_rst = self.neutron.delete_router(router_uuid)
            Reporter.REPORT_MSG("   >> Delete Router ---> %s", router_rst)
            Reporter.unit_test_stop('ok')
        except:
            Reporter.exception_err_write()
Exemplo n.º 29
0
    def get_router(self, router_opt):
        try:
            router_name = self.get_router_name(router_opt)
            if not router_name:
                return

            router_rst = self.neutron.list_routers(name=router_name)
            if not router_rst['routers']:
                Reporter.REPORT_MSG("   >> Not exist in OpenStack ---> %s, %s",
                                    router_opt, router_name)
                return

            Reporter.REPORT_MSG("   >> Router list ---> %s", router_rst)
            return router_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 30
0
 def delete_network(self, network_opt):
     Reporter.unit_test_start(True, network_opt)
     try:
         network_uuid = self.get_network_uuid(network_opt)
         if not network_uuid:
             Reporter.unit_test_stop('skip')
             return
         network_rst = self.neutron.delete_network(network_uuid)
         Reporter.REPORT_MSG("   >> Delete Network ---> %s %s", network_opt, network_uuid)
         Reporter.unit_test_stop('ok')
         return network_rst
     except:
         Reporter.exception_err_write()
Exemplo n.º 31
0
    def get_subnet_name(self, subnet_opt):
        subnet_conf = dict(self.subnet_conf)[subnet_opt]
        if not subnet_conf:
            Reporter.REPORT_MSG("   >> Not Exist Subnet in config --->")
            return

        subnet_name = ast.literal_eval(subnet_conf)['name']
        return subnet_name
Exemplo n.º 32
0
    def get_sg_name(self, sg_opt):
        sg_conf = dict(self.sg_conf)[sg_opt]
        if not sg_conf:
            Reporter.REPORT_MSG('   >> Not Exist config file ---> %s', sg_opt)
            return

        sg_name = ast.literal_eval(sg_conf)['name']
        return sg_name
Exemplo n.º 33
0
    def set_network_up(self, network_opt):
        Reporter.unit_test_start(True, network_opt)
        try:
            network_uuid = self.get_network_uuid(network_opt)
            if not network_uuid:
                Reporter.REPORT_MSG("   >> Network not find --> %s", network_opt)
                Reporter.unit_test_stop('nok')
                return
            body = {'network': {'admin_state_up': True}}
            network_rst = self.neutron.update_network(network_uuid, body)

            Reporter.REPORT_MSG("   >> Network Up Succ --> %s", network_opt)
            Reporter.unit_test_stop('ok')

            return network_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 34
0
    def set_router_up(self, router_opt):
        Reporter.unit_test_start(True, router_opt)
        try:
            router_uuid = self.get_router_uuid(router_opt)
            if not router_uuid:
                Reporter.REPORT_MSG("   >> Router not find --> %s", router_opt)
                Reporter.unit_test_stop('nok')
                return
            body = {'router': {'admin_state_up': True}}
            network_rst = self.neutron.update_router(router_uuid, body)

            Reporter.REPORT_MSG("   >> Router Up Succ --> %s", router_opt)
            Reporter.unit_test_stop('ok')

            return network_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 35
0
    def get_router(self, router_opt):
        try:
            router_name = self.get_router_name(router_opt)
            if not router_name:
                return

            router_rst = self.neutron.list_routers(name=router_name)
            if not router_rst['routers']:
                Reporter.REPORT_MSG("   >> Not exist in OpenStack ---> %s, %s",
                                    router_opt, router_name)
                return

            Reporter.REPORT_MSG("   >> Router list ---> %s", router_rst)
            return router_rst
        except:
            Reporter.exception_err_write2()
            return 'fail'
Exemplo n.º 36
0
    def delete_subnet(self, subnet_opt):
        Reporter.unit_test_start(True, subnet_opt)
        try:
            subnet_uuid = self.get_subnet_uuid(subnet_opt)
            if not subnet_uuid:
                Reporter.unit_test_stop('skip')
                return

            subnet_rst = self.neutron.delete_subnet(subnet_uuid)
            Reporter.REPORT_MSG(" >> Delete network ---> %s, %s", subnet_opt, subnet_uuid)
            Reporter.unit_test_stop('ok')
            return subnet_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 37
0
    def create_network(self, network_opt):
        Reporter.unit_test_start(True, network_opt)
        try:
            network_body = dict(self.network_conf)[network_opt]
            if not network_body:
                Reporter.REPORT_MSG("   >> Not Exist Network in config_file")
                Reporter.unit_test_stop('nok')
                return

            if self.get_network_uuid(network_opt):
                # Reporter.REPORT_MSG(" >> Already Exist same Network name")
                Reporter.unit_test_stop('skip')
            else:
                network_body = ast.literal_eval("{'network': " + network_body + "}")
                network_rst = self.neutron.create_network(body=network_body)
                Reporter.REPORT_MSG("   >> Create Network Succ ---> %s %s", network_opt, dict(network_rst).values())
                Reporter.unit_test_stop('ok')
                return network_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 38
0
 def delete_network(self, network_opt):
     Reporter.unit_test_start(True, network_opt)
     try:
         network_uuid = self.get_network_uuid(network_opt)
         if not network_uuid:
             Reporter.unit_test_stop('skip')
             return
         network_rst = self.neutron.delete_network(network_uuid)
         Reporter.REPORT_MSG("   >> Delete Network ---> %s %s", network_opt, network_uuid)
         Reporter.unit_test_stop('ok')
         return network_rst
     except:
         Reporter.exception_err_write()
Exemplo n.º 39
0
    def onos_and_openstack_check(self):
        Reporter.unit_test_start(True)
        try:
            flag = 'no'

            app_stat = self.onos.application_status(report_flag=flag)
            device_stat = self.onos.devices_status(report_flag=flag)
            token_stat = self.openstack_get_token(report_flag=flag)
            service_stat = self.openstack_get_service(report_flag=flag)

            # Reporter.NRET_PRINT("%s %s %s %s", app_stat, device_stat, token_stat, service_stat)
            if (app_stat and device_stat and token_stat and service_stat):
                Reporter.unit_test_stop('ok')
            else:
                Reporter.unit_test_stop('nok')
                if False is self.result_skip_mode:
                    Reporter.test_summary()
                    os._exit(1)
        except:
            Reporter.exception_err_write()
Exemplo n.º 40
0
    def get_subnet(self, subnet_opt):
        Reporter.unit_test_start(True, subnet_opt)
        try:
            subnet_name = self.get_subnet_name(subnet_opt)
            if not subnet_name:
                Reporter.unit_test_stop('nok')
                return

            subnet_rst = self.neutron.list_subnets(name=subnet_name)
            if not subnet_rst['subnets']:
                Reporter.REPORT_MSG("   >> Not Exist Subnet ---> %s, response: %s",
                                    subnet_name, subnet_rst)
                Reporter.unit_test_stop('nok')
                return

            Reporter.REPORT_MSG("   >> Subnet List ---> %s, response: %s",
                                subnet_opt, dict(subnet_rst).values())
            Reporter.unit_test_stop('ok')
            return subnet_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 41
0
    def delete_subnet(self, subnet_opt):
        Reporter.unit_test_start(True, subnet_opt)
        try:
            subnet_uuid = self.get_subnet_uuid(subnet_opt)
            if not subnet_uuid:
                Reporter.unit_test_stop('skip')
                return

            subnet_rst = self.neutron.delete_subnet(subnet_uuid)
            Reporter.REPORT_MSG(" >> Delete network ---> %s, %s", subnet_opt, subnet_uuid)
            Reporter.unit_test_stop('ok')
            return subnet_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 42
0
    def openstack_get_token(self, report_flag=None):
        if report_flag is None:
            Reporter.unit_test_start(True)

        try:
            auth = v2.Password(username=self.auth['username'],
                               password=self.auth['password'],
                               tenant_name=self.auth['tenant_id'],
                               auth_url=self.auth['auth_url'])
            sess = session.Session(auth=auth, timeout=5)

            token = sess.get_token()
            if not token:
                Reporter.REPORT_MSG("   >> OpentStack Authentication NOK ---> get token fail")
                if report_flag is None:
                    Reporter.unit_test_stop('nok')
                return False
            else:
                Reporter.REPORT_MSG("   >> OpenStack Authentication OK ---> user: %s, token: %s",
                                    self.auth['username'], token)

            if report_flag is None:
                Reporter.unit_test_stop('ok')
            return True

        except exceptions.AuthorizationFailure, err:
            Reporter.REPORT_MSG("   >> OpentStack Authentication Fail ---> %s", err)
            return False
Exemplo n.º 43
0
    def openstack_get_service(self, report_flag=None):
        if report_flag is None:
            Reporter.unit_test_start(True)
        try:
            auth = v2.Password(username=self.auth['username'],
                               password=self.auth['password'],
                               tenant_name=self.auth['tenant_id'],
                               auth_url=self.auth['auth_url'])
            sess = session.Session(auth=auth, timeout=5)
            keystone = client.Client(session=sess)

            service_list = [{a.name: a.enabled} for a in keystone.services.list()]

            for i in range(len(service_list)):
                if service_list[i].values()[0] is False:
                    Reporter.REPORT_MSG("   >> OpenStack Service status NOK ---> %s", service_list[i])
                    if report_flag is None:
                        Reporter.unit_test_stop('nok')
                    return False

            Reporter.REPORT_MSG("   >> OpenStack Service status OK ---> %s", service_list)

            if report_flag is None:
                Reporter.unit_test_stop('ok')

            return True

        except exceptions.AuthorizationFailure, err:
            Reporter.REPORT_MSG("   >> OpentStack Authentication Fail ---> %s", err)
            return False
Exemplo n.º 44
0
    def floatingip_associate(self, instance_opt, network_opt):
        Reporter.unit_test_start(True, instance_opt, network_opt)
        try:
            server = self.get_instance(instance_opt)
            pool_opt = ast.literal_eval(dict(self.network_conf)[network_opt])['name']

            if not server:
                Reporter.unit_test_stop('nok')
                return

            for vm_net_name in server[0].addresses.keys():
                for server_ip in server[0].addresses[vm_net_name]:
                    if str(server_ip['OS-EXT-IPS:type']) == 'floating':
                        Reporter.REPORT_MSG("   >>  %s already associated floating ip to %s network(%s)--->",
                                            instance_opt, vm_net_name, server_ip['addr'])
                        Reporter.unit_test_stop('skip')
                        return

            floatingip_list = self.nova.floating_ips.list()
            if not floatingip_list:
                Reporter.REPORT_MSG("   >> Not exist floating IPs --->")

            extra_floatingip = ''
            for a in floatingip_list:
                if not a.fixed_ip:
                    extra_floatingip = a.ip
                    break

            if not extra_floatingip:
                extra_floatingip = self.nova.floating_ips.create(pool=pool_opt).ip

            # TODO add fixed_address option
            self.nova.servers.add_floating_ip(server[0],
                                              extra_floatingip,
                                              fixed_address=None)
            Reporter.REPORT_MSG("   >> Floating IP Associate ---> %s",
                                self.nova.floating_ips.list())
            Reporter.unit_test_stop('ok')
        except:
            Reporter.exception_err_write()
Exemplo n.º 45
0
 def delete_floatingip_all(self):
     Reporter.unit_test_start(True)
     try:
         floatingip_list = self.get_floatingip_list()
         if not floatingip_list:
             Reporter.REPORT_MSG("   >> Not exist Floating IP --->")
             Reporter.unit_test_stop('skip')
             return
         for f in floatingip_list:
             self.nova.floating_ips.delete(f)
         Reporter.REPORT_MSG("   >> All Floating IP Delete Succ --->")
         Reporter.unit_test_stop('ok')
         return
     except:
         Reporter.exception_err_write()
Exemplo n.º 46
0
    def each_device_status(self, conn_info):
        try:
            dev_list = self.device_info(conn_info)
            if None is dev_list:
                Reporter.REPORT_MSG('   >> Device Get Fail from [%s] -->', conn_info['host'])
                return False

            dev_cnt = 0
            for i in range(len(dev_list)):
                dev_info_dic = dict(dev_list[i])
                proto = dict(dev_info_dic['annotations']).get('protocol')
                if None is proto:
                    continue
                dev_cnt += 1
                if False is dev_info_dic['available']:
                    Reporter.REPORT_MSG('   >> ONOS Device[%s] Status NOK [%s] ', dev_info_dic['id'], conn_info['host'])
                    return False

                # Port status(br-int)
                if 'of' in dev_info_dic['id']:
                    port_status = self.port_info(conn_info, dev_info_dic['id'])
                    if not port_status:
                        return False

                    status = 0
                    for x in list(port_status):
                        if x == 'br-int' :
                            continue
                        else:
                            if not port_status[x]:
                                Reporter.REPORT_MSG('   >> ONOS Device[%s]\' Port(%s) status is False [%s]',
                                                    dev_info_dic['id'], x, conn_info['host'])
                                return False

            Reporter.REPORT_MSG('   >> ONOS Device/Port status OK [%s] ', conn_info['host'])
            return True
        except:
            Reporter.exception_err_write()
Exemplo n.º 47
0
    def port_info(self, conn_info, dev_id):
        try:
            conn = self.onos_create_session(conn_info)
            url = 'http://' + conn_info['host'] + ':8181/onos/v1/devices/' + dev_id + '/ports'
            header = {'Accept': 'application/json'}
            # print json.dumps(conn.get(url, headers=header).json(),indent=4, separators=('',':'))
            ret = json.dumps(conn.get(url, headers=header, timeout= self._config.get_onos_timeout()).json(),
                             ensure_ascii=False, sort_keys=False).encode('utf-8')

            result = dict()
            for x in json.loads(ret)['ports']:
                result[x['annotations']['portName']] = x['isEnabled']

            if not len(result):
                Reporter.REPORT_MSG('   >> Device[%s] Get port fail from [%s] ',
                                    dev_id, conn_info['host'])
                return

            return result

        except:
            Reporter.exception_err_write()
            return
Exemplo n.º 48
0
    def delete_instance(self, instance_opt):
        Reporter.unit_test_start(True, instance_opt)
        try:
            instance_list = self.get_instance(instance_opt)
            if not instance_list:
                Reporter.unit_test_stop('skip')
                return
            for i in instance_list:
                self.nova.servers.delete(i)
                # time.sleep(5)

            Reporter.REPORT_MSG("   >> Delete Instance ---> %s", instance_opt)
            Reporter.unit_test_stop('ok')
            return
        except:
            Reporter.exception_err_write()
Exemplo n.º 49
0
    def remove_router_interface(self, router_opt, subnet_opt):
        Reporter.unit_test_start(True, router_opt, subnet_opt)
        try:
            router_uuid = self.get_router_uuid(router_opt)
            if not router_uuid:
                Reporter.REPORT_MSG("   >> Router Not Exist --->> %s", router_opt)
                Reporter.unit_test_stop('nok')
                return

            subnet_uuid = self.get_subnet_uuid(subnet_opt)
            if not subnet_uuid:
                Reporter.REPORT_MSG("   >> Subnet Not Exist --->> %s", router_opt)
                Reporter.unit_test_stop('nok')
                return

            router_if_body = {'subnet_id': subnet_uuid}
            router_if_rst = self.neutron.remove_interface_router(router_uuid, router_if_body)
            Reporter.REPORT_MSG("   >> Remove Router Interface ---> %s, %s",
                                router_opt, subnet_opt)
            Reporter.unit_test_stop('ok')
            return router_if_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 50
0
    def set_network_down(self, network_opt):
        Reporter.unit_test_start(True, network_opt)
        try:
            network_uuid = self.get_network_uuid(network_opt)
            if not network_uuid:
                Reporter.unit_test_stop('nok')
                return
            body = {'network': {'admin_state_up': False}}
            network_rst = self.neutron.update_network(network_uuid, body)

            Reporter.REPORT_MSG("   >> Network Down Succ --> %s", network_opt)
            Reporter.unit_test_stop('ok')

            return network_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 51
0
    def set_router_up(self, router_opt):
        Reporter.unit_test_start(True, router_opt)
        try:
            router_uuid = self.get_router_uuid(router_opt)
            if not router_uuid:
                Reporter.REPORT_MSG("   >> Router not find --> %s", router_opt)
                Reporter.unit_test_stop('nok')
                return
            body = {'router': {'admin_state_up': True}}
            network_rst = self.neutron.update_router(router_uuid, body)

            Reporter.REPORT_MSG("   >> Router Up Succ --> %s", router_opt)
            Reporter.unit_test_stop('ok')

            return network_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 52
0
    def floating_ip_check(self, inst1):
        Reporter.unit_test_start(False)
        try:
            # floating ip
            floating_ip = self.instance.get_instance_floatingip(inst1)
            if None is floating_ip:
                Reporter.REPORT_MSG('   >> Get floating_ip[%s] fail', floating_ip)
                Reporter.unit_test_stop('nok', False)
                return False
            ping_result = []
            sucs_cnt = 0
            (exitstatus, outtext) = commands.getstatusoutput('uname -a')
            if 'Linux' in outtext:
                cmd = 'ping ' + floating_ip + ' -w 1'
            else:
                cmd = 'ping -t 1 ' + floating_ip

            for i in range(self.ping_timeout):
                (exitstatus, outtext) = commands.getstatusoutput(cmd)
                ping_result.append(outtext)
                if 'from ' + floating_ip in outtext:
                    sucs_cnt += 1
                    if 2 is sucs_cnt:
                        break

            if 2 is sucs_cnt:
                Reporter.REPORT_MSG('   >> result : local --> %s : ok', floating_ip)
                time.sleep(5)
                Reporter.unit_test_stop('ok', False)
                return True
            else:
                Reporter.REPORT_MSG('   >> result : local --> %s : nok', floating_ip)
                Reporter.unit_test_stop('nok', False)
            return False
        except:
            Reporter.exception_err_write()
Exemplo n.º 53
0
    def set_port_up(self, instance_opt, network_opt):
        Reporter.unit_test_start(True, instance_opt, network_opt)
        try:
            port_uuid = self.get_port_uuid(instance_opt, network_opt)
            if not port_uuid:
                Reporter.REPORT_MSG("   >> Port Not find --> %s, %s",
                                    instance_opt, network_opt)
                Reporter.unit_test_stop('nok')
                return

            body = {'port': {'admin_state_up': True}}
            port_rst = []
            for i in range(len(port_uuid)):
                port_rst.append(self.neutron.update_port(port_uuid[i], body))

            Reporter.REPORT_MSG("   >> Port Down Succ --> %s", port_uuid)
            Reporter.unit_test_stop('ok')
            return port_rst
        except:
            Reporter.exception_err_write()
Exemplo n.º 54
0
    def application_status(self, report_flag=None):
        if report_flag is None:
            Reporter.unit_test_start(True)
        try:
            onos_info = self._config.get_onos_info()
            conn_info = {}
            state_info = {}

            for onos_ip in onos_info.onos_service_ip.split(','):
                state_list = []
                conn_info['host'] = onos_ip
                conn_info['user'] = onos_info.user_id
                conn_info['password'] = onos_info.password

                for app in onos_info.app_list:
                    # Reporter.NRET_PRINT("aaa %s", app)
                    ret = self.app_info(conn_info, 'org.onosproject.' + app)
                    state_info[app] = ret; state_list.append(ret)
                # ret = self.app_info(conn_info, 'org.onosproject.scalablegateway')
                # state_info['scalablegateway'] = ret; state_list.append(ret)
                # ret = self.app_info(conn_info, 'org.onosproject.openstacknode')
                # state_info['openstacknode'] = ret; state_list.append(ret)

                # if 'ACTIVE' not in state_list:
                if state_list.count('ACTIVE') != len(state_list):
                    Reporter.REPORT_MSG('   >> ONOS Application NOK [%s]: %s', onos_ip, state_info)
                    if report_flag is None:
                        Reporter.unit_test_stop('nok')
                    return False
                else:
                    Reporter.REPORT_MSG('   >> ONOS Application OK [%s]: %s', onos_ip, state_info)

            if report_flag is None:
                Reporter.unit_test_stop('ok')

            return True
        except:
            Reporter.exception_err_write()
            return False
Exemplo n.º 55
0
    def devices_status(self, report_flag=None):
        if report_flag is None:
            Reporter.unit_test_start(True)
        try:
            onos_info = self._config.get_onos_info()
            conn_info = {}
            for onos_ip in onos_info.onos_service_ip.split(','):
                conn_info['host'] = onos_ip
                conn_info['user'] = onos_info.user_id
                conn_info['port'] = onos_info.ssh_port
                conn_info['password'] = onos_info.password
                ret = self.each_device_status(conn_info)
                if False is ret:
                    if report_flag is None:
                        Reporter.unit_test_stop('nok')
                    return False

            if report_flag is None:
                Reporter.unit_test_stop('ok')

            return True
        except:
            Reporter.exception_err_write()
            return False
Exemplo n.º 56
0
    def onos_application_status(self):
        # onos status
        Reporter.unit_test_start()
        conn_info = {}
        # onos_info = self.config.get_onos_info()

        for onos_ip in self.onos_info.onos_list:
            conn_info['host'] = onos_ip
            conn_info['user'] = self.onos_info.user_id
            conn_info['port'] = self.onos_info.ssh_port
            conn_info['password'] = self.onos_info.password
            ret = self.apps_status(conn_info)
            if 0 is ret:
                Reporter.unit_test_stop('nok')
                return False

        Reporter.unit_test_stop('ok')
Exemplo n.º 57
0
    def create_instance(self, instance_opt, network_opt, sg_opt):
        Reporter.unit_test_start(True, instance_opt, network_opt, sg_opt)
        try:
            config_value = self.find_instance(instance_opt)
            if not config_value:
                Reporter.unit_test_stop('nok')
                return

            instance_rst = self.nova.servers.list(search_opts={'name': config_value['name']})
            if instance_rst:
                Reporter.REPORT_MSG("   >> Already exist in OpenStack ---> %s", instance_rst)
                Reporter.unit_test_stop('skip')
                return

            image = self.nova.images.find(name=config_value['image'])
            flavor = self.nova.flavors.find(name=config_value['flavor'])

            # Get openstack network name from network config
            net_name_list = []
            network_opt = network_opt.split(',')
            for a in network_opt:
                net_conf_body = ast.literal_eval(dict(self.network_conf)[a.strip()])
                if not net_conf_body:
                    Reporter.REPORT_MSG("   >> Not exist in config file ---> %s", network_opt)
                    Reporter.unit_test_stop('nok')
                    return
                net_name_list.append(net_conf_body['name'])

            # Get network uuid from openstack neutron and make nics list
            nics_list = []
            for a in net_name_list:
                nics_list.append({'net-id':  self.nova.networks.find(label=a).id})

            if sg_opt is '':
                sg_list = ['default']
            else:
                sg_list = [ast.literal_eval(dict(self.sg_config)[sg_opt])['name']]

            # create instance
            instance_rst = self.nova.servers.create(name=config_value['name'],
                                                    image=image,
                                                    flavor=flavor,
                                                    availability_zone=config_value['zone'],
                                                    nics=nics_list,
                                                    security_groups=sg_list)

            Reporter.REPORT_MSG("   >> Create Succ ---> %s", instance_rst)
            Reporter.unit_test_stop('ok')
            return instance_rst
        except:
            Reporter.exception_err_write()