示例#1
0
    def attach(self, target_nic_uuids):
        added_l3_uuid = []
        for nic in target_nic_uuids:
            l3_uuid = test_lib.lib_get_l3_uuid_by_nic(nic)
            self._add_nic(l3_uuid, nic)
            #In zstack, need attach Nic's L3 to SG, before add Nic to SG
            # If SG has been attached to L3, it should not be attached again.
            if l3_uuid in added_l3_uuid:
                continue
            conditions = res_ops.gen_query_conditions('uuid', '=', self.security_group.uuid)
            sg = res_ops.query_resource(res_ops.SECURITY_GROUP, conditions)[0]
            if l3_uuid in sg.attachedL3NetworkUuids:
                added_l3_uuid.append(l3_uuid)
                continue
            added_l3_uuid.append(l3_uuid)
            
            net_ops.attach_security_group_to_l3(self.security_group.uuid, l3_uuid)

        net_ops.add_nic_to_security_group(self.security_group.uuid, target_nic_uuids)
        super(ZstackTestSecurityGroup, self).attach(target_nic_uuids)
示例#2
0
    def create(self, target_vm=None):
        if not self.pf_creation_option.get_vm_nic_uuid():
            self.state = pf_header.DETACHED
        else:
            if not self.pf_creation_option.get_vip_uuid():
                l3_uuid = test_lib.lib_get_l3_uuid_by_nic(self.pf_creation_option.get_vm_nic_uuid())
                if not 'PortForwarding' in test_lib.lib_get_l3_service_type(l3_uuid):
                    test_util.test_fail('[l3:] %s is not available PortForwarding network for [vm:] %s' % (l3_uuid, target_vm.get_vm().uuid))
                vr = test_lib.lib_find_vr_by_l3_uuid(l3_uuid)[0]
                vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr)
                vip = net_ops.create_vip(vr_pub_nic.l3NetworkUuid)
                self.pf_creation_option.set_vip_uuid(vip.uuid)
            self.state = pf_header.ATTACHED
            if not target_vm:
                test_util.test_fail('You forget to add target_vm object when calling pf.create(target_vm). ')
                    
        self.port_forwarding = net_ops.create_port_forwarding(self.pf_creation_option)
        self.target_vm = target_vm
        super(ZstackTestPortForwarding, self).create()

        return self.port_forwarding
def stopped_vm_operations(vm,bss):
   
   vm_uuid = vm.get_vm().uuid
   ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
   vm_ops.stop_vm(vm_uuid)
   #Change vm's instanceoffering
   vm_ops.update_vm(vm_uuid,2,2048*1024*1024)
   
   #Change vm's status
   ha_ops.set_vm_instance_ha_level(vm_uuid,'neverstop')
   vm_ops.stop_vm(vm_uuid)
   ha_ops.del_vm_instance_ha_level(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   if ps.type != 'LocalStorage':
      target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid
      if target_host_uuid != None:
         vm_ops.start_vm_with_target_host(vm_uuid,target_host_uuid)
   #vm_ops.stop_vm(vm_uuid)
   vm_ops.destroy_vm(vm_uuid)
   vm_ops.recover_vm(vm_uuid)
   vm_ops.reinit_vm(vm_uuid)

   #clone
   vm_ops.clone_vm(vm_uuid,['vm-1','vm-2','vm-3'],'InstantStart')

   #migrate
   vm_ops.start_vm(vm_uuid)
   candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
   vm_ops.stop_vm(vm_uuid)
   migrate_host_uuids = []
   if candidate_hosts != None:
      for host in candidate_hosts.inventories:
         migrate_host_uuids.append(host.uuid)
      if ps.type == 'LocalStorage':
         vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
         #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])		
         vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0])
         test_util.test_logger('migrate vm success')
   
   #resize root volume
   vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
   vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
   set_size = 1024*1024*1024*5
   vol_ops.resize_volume(vol_uuid, set_size)
   vm.update()
   vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
   if set_size != vol_size_after:
      test_util.test_fail('Resize Root Volume failed, size = %s' % vol_size_after)
   test_util.test_logger('resize vm success')
   
   #storage migrate
         
   #change vm image
   image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid)
   image_uuids = []
   for image in image_list.inventories:
      image_uuids.append(image.uuid)
   vm_ops.change_vm_image(vm_uuid,image_uuids[0])
   vm.update()
   
   #update vm nic mac
   nic_uuid = vm.get_vm().vmNics[0].uuid
   mac = 'fa:4c:ee:9a:76:00'
   vm_ops.update_vm_nic_mac(nic_uuid,mac)

   #set/del static ip
   l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid)
   vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid, vm.get_vm().vmNics[0].ip)
   vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid)
  
   #snapshot operations
   sp_option = test_util.SnapshotOption()
   vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
   root_volume_uuid = vm_root_volume_inv.uuid
   sp_option.set_volume_uuid(root_volume_uuid)
   sp = vol_ops.create_snapshot(sp_option)
   vol_ops.use_snapshot(sp.uuid)
   vol_ops.delete_snapshot(sp.uuid)

   common_operations(vm,bss,'stopped')
   vm.destroy()
   vm.expunge()
def stopped_vm_operations(vm, bss):

    vm_uuid = vm.get_vm().uuid
    ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm())
    vm_ops.stop_vm(vm_uuid)
    #Change vm's instanceoffering
    vm_ops.update_vm(vm_uuid, 2, 2048 * 1024 * 1024)

    #Change vm's status
    ha_ops.set_vm_instance_ha_level(vm_uuid, 'neverstop')
    vm_ops.stop_vm(vm_uuid)
    ha_ops.del_vm_instance_ha_level(vm_uuid)
    vm_ops.stop_vm(vm_uuid)
    if ps.type != 'LocalStorage':
        target_host_uuid = test_lib.lib_find_random_host(vm.get_vm()).uuid
        if target_host_uuid != None:
            vm_ops.start_vm_with_target_host(vm_uuid, target_host_uuid)
    #vm_ops.stop_vm(vm_uuid)
    vm_ops.destroy_vm(vm_uuid)
    vm_ops.recover_vm(vm_uuid)
    vm_ops.reinit_vm(vm_uuid)

    #clone
    vm_ops.clone_vm(vm_uuid, ['vm-1', 'vm-2', 'vm-3'], 'InstantStart')

    #migrate
    vm_ops.start_vm(vm_uuid)
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
    vm_ops.stop_vm(vm_uuid)
    migrate_host_uuids = []
    if candidate_hosts != None:
        for host in candidate_hosts.inventories:
            migrate_host_uuids.append(host.uuid)
        if ps.type == 'LocalStorage':
            vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
            #vm_ops.migrate_vm(vm_uuid,migrate_host_uuids[0])
            vol_ops.migrate_volume(vol_uuid, migrate_host_uuids[0])
            test_util.test_logger('migrate vm success')

    #resize root volume
    vol_size = test_lib.lib_get_root_volume(vm.get_vm()).size
    vol_uuid = test_lib.lib_get_root_volume(vm.get_vm()).uuid
    set_size = 1024 * 1024 * 1024 * 5
    vol_ops.resize_volume(vol_uuid, set_size)
    vm.update()
    vol_size_after = test_lib.lib_get_root_volume(vm.get_vm()).size
    if set_size != vol_size_after:
        test_util.test_fail('Resize Root Volume failed, size = %s' %
                            vol_size_after)
    test_util.test_logger('resize vm success')

    #storage migrate

    #change vm image
    image_list = vm_ops.get_image_candidates_for_vm_to_change(vm_uuid)
    image_uuids = []
    for image in image_list.inventories:
        image_uuids.append(image.uuid)
    vm_ops.change_vm_image(vm_uuid, image_uuids[0])
    vm.update()

    #update vm nic mac
    nic_uuid = vm.get_vm().vmNics[0].uuid
    mac = 'fa:4c:ee:9a:76:00'
    vm_ops.update_vm_nic_mac(nic_uuid, mac)

    #set/del static ip
    l3network_uuid = test_lib.lib_get_l3_uuid_by_nic(nic_uuid)
    vm_ops.change_vm_static_ip(vm_uuid, l3network_uuid,
                               vm.get_vm().vmNics[0].ip)
    vm_ops.delete_vm_static_ip(vm_uuid, l3network_uuid)

    #snapshot operations
    sp_option = test_util.SnapshotOption()
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    root_volume_uuid = vm_root_volume_inv.uuid
    sp_option.set_volume_uuid(root_volume_uuid)
    sp = vol_ops.create_snapshot(sp_option)
    vol_ops.use_snapshot(sp.uuid)
    vol_ops.delete_snapshot(sp.uuid)

    common_operations(vm, bss, 'stopped')
    vm.destroy()
    vm.expunge()