예제 #1
0
def tearDown(fuel_ip,controller_node,subnet_name):
    '''after test,clean network'''
    cmd_delete_net="source /root/openrc && neutron subnet-delete %s"%subnet_name
    print cmd_delete_net
    try:
        remote_cmd(fuel_ip=fuel_ip, node=controller_node, cmd=cmd_delete_net)
        print "env_cleaned",time.ctime()
    except Exception, error:
        print error,"location: clean up"
예제 #2
0
def _copy_image_from_url(fuel_ip,controller_node,image_url):
    cmd_wget="wget %s" %image_url
    cmd_check_firmaware="ls | grep %s" %image_url.split("/")[-1]
    i=0
    '''if not firmware in controller node, download from url, try 3 times, if after download still no firmware, return false'''
    while not remote_cmd(fuel_ip=fuel_ip,node=controller_node,cmd=cmd_check_firmaware) and i<3:
        remote_cmd(fuel_ip=fuel_ip,node=controller_node,cmd=cmd_wget)
        i+=1
    return i<3
예제 #3
0
파일: boot_vm.py 프로젝트: kyonasa/reach
def tearDown(fuel_ip, controller_node, vm_name):
    '''after test,clean all vm ,flavor ,keypair that used in case, not include image'''
    name = vm_name
    cmd_delete_vm = "source /root/openrc && nova delete %s" % name
    try:
        remote_cmd(fuel_ip=fuel_ip, node=controller_node, cmd=cmd_delete_vm)
        print "env_cleaned", time.ctime()
    except Exception, error:
        print error, "location: clean up"
예제 #4
0
def tearDown(fuel_ip,controller_node,image_uuid):
    '''after test,clean image'''
    cmd_delete_image="source /root/openrc && glance image-delete %s"%image_uuid
    print cmd_delete_image
    try:
        remote_cmd(fuel_ip=fuel_ip, node=controller_node, cmd=cmd_delete_image)
        print "env_cleaned",time.ctime()
    except Exception, error:
        print error,"location: clean up"
예제 #5
0
def tearDown(fuel_ip, controller_node, keypair, key_path):
    '''after test,clean all vm ,flavor ,keypair that used in case, not include image'''
    cmd_delete_keypair = "source /root/openrc && openstack keypair delete %s" % keypair
    cmd_delete_keypath = "rm -rf %s" % key_path
    try:
        remote_cmd(fuel_ip=fuel_ip,
                   node=controller_node,
                   cmd=cmd_delete_keypair)
        remote_cmd(fuel_ip=fuel_ip,
                   node=controller_node,
                   cmd=cmd_delete_keypath)
        print "env_cleaned", time.ctime()
    except Exception, error:
        print error, "location: clean up"
예제 #6
0
def create_net_cli(fuel_ip,
                   controller_node,
                   net_name="test-mengph-0",
                   ra_type="ra-advertisement",
                   type="vlan",
                   physical_network="physnet2",
                   segmentation_id="1010",
                   vlan_transparent=True,
                   mtu=9000):
    cmd_create_net="source /root/openrc && neutron net-create %s --ra-type %s --provider:network_type %s " \
                   "--provider:physical_network %s --provider:segmentation_id %s --vlan-transparent %s " \
                   "--mtu %d" % (net_name,ra_type,type,physical_network,segmentation_id,vlan_transparent,mtu)
    print cmd_create_net
    print remote_cmd(fuel_ip=fuel_ip, node=controller_node, cmd=cmd_create_net)
예제 #7
0
def create_image_from_local(fuel_ip,controller_node,keystone_url,image_url="http://10.121.136.222/centos6.8_gb.qcow2",image_name="mengph"):
    if not _copy_image_from_url(fuel_ip=fuel_ip, controller_node=controller_node,image_url=image_url):
        return False
    res=_check_image(fuel_ip=fuel_ip, controller_node=controller_node,image_name=image_name,keystone_url=keystone_url)
    print res
    if res:
        return res
    try:
        _set_api_version(fuel_ip=fuel_ip, controller_node=controller_node,api_v="2")
        cmd_create_logic="source /root/openrc && glance image-create --file /root/%s --disk-format raw --container-format bare --name %s" %(image_url.split("/")[-1],image_name)
        print cmd_create_logic
        print remote_cmd(fuel_ip=fuel_ip, node=controller_node,cmd=cmd_create_logic)
    except Exception,error:
        print error,"loaction: create image_from_local"
예제 #8
0
def create_priv_key(fuel_ip, controller_node, key, key_path):
    '''fucntion for create an openstack keypair for test vm'''
    cmd_create_priv_key = "source /root/openrc && openstack keypair create %s > %s" % (
        key, key_path)
    cmd_chmod = " chmod 600 %s" % key_path
    try:
        print cmd_create_priv_key
        keypair = remote_cmd(fuel_ip=fuel_ip,
                             node=controller_node,
                             cmd=cmd_create_priv_key)
        remote_cmd(fuel_ip=fuel_ip, node=controller_node, cmd=cmd_chmod)
        return True
    except Exception, error:
        print error
        return False
예제 #9
0
def update_net_cli(fuel_ip, controller_node, net_name, element):
    '''uptade net mtu or/and qos'''
    updates = ""
    if "mtu" in element.keys():
        updates += " --mtu %s" % element["mtu"]
    if "qos" in element.keys():
        if element["qos"] == "no":
            updates += " --no-qos-policy"
        else:
            updates += " --qos-policy %s" % element["qos"]
    cmd_update_net = "source /root/openrc && neutron net-update %s" % net_name + updates
    print cmd_update_net
    try:
        remote_cmd(fuel_ip=fuel_ip, node=controller_node, cmd=cmd_update_net)
    except Exception, error:
        raise error
예제 #10
0
파일: interface.py 프로젝트: kyonasa/reach
 def check_port(self, fuel_ip, controller_node, uuid=None):
     if not uuid:
         uuid = self.id
     cmd_check_port_cli = "source /root/openrc && neutron port-show %s -f json" % uuid
     try:
         port = remote_cmd(fuel_ip=fuel_ip,
                           node=controller_node,
                           cmd=cmd_check_port_cli)
     except Exception, error:
         raise error
예제 #11
0
def check_subnet_cli(fuel_ip,controller_node,net_name):
    cmd_check_net="source /root/openrc && neutron subnet-show %s -f json" %net_name
    try:
        network=remote_cmd(fuel_ip=fuel_ip,node=controller_node,cmd=cmd_check_net)
        if not network:
            return None
        try:
            json.loads(network)["id"]
            return json.loads(network)
        except:
            return fuck_trans_stdout_to_correct(network)
    except Exception,error:
        print error,"loacton:check net"
        raise error
예제 #12
0
파일: interface.py 프로젝트: kyonasa/reach
 def create_port(self, fuel_ip, controller_node, network=None):
     cmd_create_port_cli = "source /root/openrc && neutron port-create"
     args = []
     for item in self.__dict__.items():
         if item[1]:
             if item[0] == "network_id" and not network:
                 network = item[1]
             elif item[0] == "id":
                 print "port exist"
                 return
             else:
                 args.append(item)
     if args:
         for arg in args:
             cmd_create_port_cli += (" --" + arg[0].replace("_", "-") +
                                     " " + arg[1])
     cmd_create_port_cli += " %s" % network
     print cmd_create_port_cli
     try:
         remote_cmd(fuel_ip=fuel_ip,
                    node=controller_node,
                    cmd=cmd_create_port_cli)
     except Exception, error:
         raise error
예제 #13
0
def _check_image(fuel_ip,controller_node,image_name="cyborg_image",keystone_url=""):
    '''check the status of image '''
    try:
        glance_client=glance_hello.setup(keystone_url)
        image=glance_hello.image_get(glance_client,name=image_name)
        image["id"]
        if image:
            return image
        else:
            return []
    except Exception,error:
        print error,"location: check_image"
        cmd_check_image="source /root/openrc && openstack image show %s -f json" %image_name
        image=remote_cmd(fuel_ip=fuel_ip,node=controller_node,cmd=cmd_check_image)
        if not image:
            return []
        try:
            json.loads(image)["id"]
            return [json.loads(image)]
        except:
            return [fuck_trans_stdout_to_correct(image)]
예제 #14
0
                if key in specs:
                    specs[key] += ("," + value)
                else:
                    specs[key] = value
            for key in specs.keys():
                cmd_set_flavor_spec = "source /root/openrc && openstack flavor set %s --property %s" % (
                    flavor, key + "=" + specs[key])
                print cmd_set_flavor_spec
                remote_cmd(fuel_ip=fuel_ip,
                           node=controller_node,
                           cmd=cmd_set_flavor_spec)
    except Exception, error:
        print error
    finally:
        tmp_res = remote_cmd(fuel_ip=fuel_ip,
                             node=controller_node,
                             cmd=cmd_check_flavor)
        try:
            json.loads(tmp_res)["id"]
            return json.loads(tmp_res)
        except:
            return fuck_trans_stdout_to_correct(tmp_res)


def tearDown(fuel_ip, controller_node, flavor_name):
    '''after test,clean all vm ,flavor ,keypair that used in case, not include image'''
    flavor = flavor_name
    cmd_delete_flavor = "source /root/openrc && nova flavor-delete %s" % flavor
    try:
        remote_cmd(fuel_ip=fuel_ip,
                   node=controller_node,
예제 #15
0
def _set_api_version(fuel_ip,controller_node,api_v="2"):
    cmd_set_api_to_x="sed -i '$d' openrc && sed -i '$a export OS_IMAGE_API_VERSION='%s'' openrc" %api_v
    remote_cmd(fuel_ip=fuel_ip,node=controller_node,cmd=cmd_set_api_to_x)
예제 #16
0
def _create_image(fuel_ip,controller_node,image_name,image_url):
    '''create an image from url'''
    cmd_create_image = "source /root/openrc && glance image-create --name %s --copy-from %s --disk-format qcow2 --container-format bare  --progress" %(image_name,image_url)
    print cmd_create_image
    print remote_cmd(fuel_ip=fuel_ip, node=controller_node, cmd=cmd_create_image)