def testName(self): url = aliyunagent._build_url_for_test([ virtualrouter_plugin.VirtualRouterPlugin. VR_KVM_CREATE_BOOTSTRAP_ISO_PATH ]) info = virtualrouter_plugin.BootstrapIsoInfo() info.managementNicGateway = "192.168.1.1" info.managementNicIp = "192.168.1.10" info.managementNicMac = "50:E5:49:C9:65:A3" info.managementNicNetmask = "255.255.255.0" cmd = virtualrouter_plugin.CreateVritualRouterBootstrapIsoCmd() cmd.isoInfo = info cmd.isoPath = '/tmp/vr.iso' rsp = http.json_dump_post(url, cmd, headers={ http.TASK_UUID: uuidhelper.uuid(), http.CALLBACK_URI: self.CALLBACK_URL }) time.sleep(2) cmd = virtualrouter_plugin.DeleteVirtualRouterBootstrapIsoCmd() cmd.isoPath = '/tmp/vr.iso' url = aliyunagent._build_url_for_test([ virtualrouter_plugin.VirtualRouterPlugin. VR_KVM_DELETE_BOOTSTRAP_ISO_PATH ]) rsp = http.json_dump_post(url, cmd, headers={ http.TASK_UUID: uuidhelper.uuid(), http.CALLBACK_URI: self.CALLBACK_URL }) time.sleep(2) self.service.stop()
def testName(self): cmd = vm_plugin.StartVmCmd() cmd.vmName = 'test' cmd.vmUuid = uuidhelper.uuid() self.uuid = cmd.vmUuid cmd.cpuNum = 2 cmd.cpuSpeed = 3000 cmd.memory = 3221225472 cmd.rootVolumePath = '/home/root/images/volumes/kvmubuntu.img' cmd.bootDev = 'hd' cmd.timeout = 30 nic = vm_plugin.NicTO() nic.mac = 'fa:33:f8:5f:00:00' nic.bridgeName = 'virbr0' nic.deviceId = 0 cmd.nics.append(nic) url = aliyunagent._build_url_for_test([vm_plugin.KVM_START_VM_PATH]) rsp = http.json_dump_post(url, cmd, headers={ http.TASK_UUID: uuidhelper.uuid(), http.CALLBACK_URI: self.CALLBACK_URL }) time.sleep(30) self.service.stop()
def testName(self): self.mount() cmd = nfs_primarystorage_plugin.DownloadImageToCacheFromSftpBackupStorageCmd( ) p = os.path.expanduser('~/.ssh/id_rsa') with open(p, 'r') as fd: sshkey = fd.read() cmd.installUrl = '/tmp/test.qcow2' cmd.sftpBackupStorageHostName = "root@localhost" cmd.sftpBackupStorageSshKey = sshkey cmd.templatePath = '/home/root/test.qcow2' cmd.timeout = 300 url = aliyunagent._build_url_for_test([ nfs_primarystorage_plugin. DOWNLOAD_IMAGE_FROM_SFTP_BACKUP_STORAGE_PATH ]) rsp = http.json_dump_post(url, cmd, headers={ http.TASK_UUID: uuidhelper.uuid(), http.CALLBACK_URI: self.CALLBACK_URL }) time.sleep(10) self.service.stop() linux.umount_by_url(self.NFS_URL)
def test_mount_failure(self): cmd = nfs_primarystorage_plugin.MountCmd() cmd.url = 'this_is_a_wrong_path' cmd.mountPath = os.path.join('/mnt', uuidhelper.uuid()) callurl = aliyunagent._build_url_for_test([nfs_primarystorage_plugin.MOUNT_PATH]) ret = http.json_dump_post(callurl, cmd) rsp = jsonobject.loads(ret) self.assertFalse(rsp.success, rsp.error)
def test_check_physical_network_interface(self): url = aliyunagent._build_url_for_test([network_plugin.CHECK_PHYSICAL_NETWORK_INTERFACE_PATH]) logger.debug('calling %s' % url) cmd = network_plugin.CheckPhysicalNetworkInterfaceCmd() cmd.interfaceNames = ['p5p1'] ret = http.json_dump_post(url, body=cmd) rsp = jsonobject.loads(ret) self.assertTrue(rsp.success)
def test_unmount_always_success(self): cmd = nfs_primarystorage_plugin.UnmountCmd() cmd.url = NFS_URL cmd.mountPath = '/not_mounted_path' callurl = aliyunagent._build_url_for_test([nfs_primarystorage_plugin.UNMOUNT_PATH]) ret = http.json_dump_post(callurl, cmd) rsp = jsonobject.loads(ret) self.assertTrue(rsp.success, rsp.error) self.assertFalse(linux.is_mounted(path=cmd.mountPath))
def test_hostfact(self): url = aliyunagent._build_url_for_test([host_plugin.HOSTFACT_PATH]) cmd = HostFactCmd() ret = http.json_dump_post(url, body=cmd) rsp = jsonobject.loads(ret) self.assertTrue(rsp.success) self.assertEqual(host_plugin._get_cpu_num(), rsp.cpuNum) self.assertEqual(host_plugin._get_cpu_speed(), rsp.cpuSpeed) self.assertEqual(host_plugin._get_total_memory(), rsp.totalMemory)
def mount(self): cmd = nfs_primarystorage_plugin.MountCmd() cmd.url = self.NFS_URL cmd.mountPath = os.path.join('/mnt', uuidhelper.uuid()) callurl = aliyunagent._build_url_for_test([nfs_primarystorage_plugin.MOUNT_PATH]) ret = http.json_dump_post(callurl, cmd) rsp = jsonobject.loads(ret) self.assertTrue(rsp.success, rsp.error) self.assertTrue(linux.is_mounted(cmd.url, cmd.mountPath))
def callback(self, req): rsp = jsonobject.loads(req[http.REQUEST_BODY]) print jsonobject.dumps(rsp) cmd = vm_plugin.StopVmCmd() cmd.uuid = self.uuid cmd.timeout = 30 url = aliyunagent._build_url_for_test([vm_plugin.KVM_STOP_VM_PATH]) rsp = http.json_dump_post(url, cmd, headers={http.TASK_UUID:uuidhelper.uuid(), http.CALLBACK_URI:self.CALLBACK_URL2})
def testName(self): self.mount() cmd = nfs_primarystorage_plugin.CreateEmptyVolumeCmd() cmd.accountUuid = uuidhelper.uuid() cmd.hypervisorType = 'KVM' cmd.installUrl = '/tmp/emptyvolume.qcow2' cmd.name = 'testEmptyVolume' cmd.size = '1410400256' cmd.uuid = uuidhelper.uuid() url = aliyunagent._build_url_for_test([nfs_primarystorage_plugin.CREATE_EMPTY_VOLUME_PATH]) rsp = http.json_dump_post(url, cmd, headers={http.TASK_UUID:uuidhelper.uuid(), http.CALLBACK_URI:self.CALLBACK_URL}) time.sleep(5) self.service.stop() linux.umount_by_url(self.NFS_URL)
def testName(self): self.mount() cmd = nfs_primarystorage_plugin.GetCapacityCmd() url = aliyunagent._build_url_for_test( [nfs_primarystorage_plugin.GET_CAPACITY_PATH]) rsp = http.json_dump_post(url, cmd, headers={ http.TASK_UUID: uuidhelper.uuid(), http.CALLBACK_URI: self.CALLBACK_URL }) time.sleep(5) self.service.stop() linux.umount_by_url(self.NFS_URL)
def testName(self): url = aliyunagent._build_url_for_test( [network_plugin.KVM_REALIZE_L2NOVLAN_NETWORK_PATH]) logger.debug('calling %s' % url) cmd = network_plugin.CreateBridgeCmd() cmd.physicalInterfaceName = 'eth0' cmd.bridgeName = 'br_eth0' rsp = http.json_dump_post(url, cmd, headers={ http.TASK_UUID: uuidhelper.uuid(), http.CALLBACK_URI: self.CALLBACK_URL }) time.sleep(2) self.service.stop()
def testName(self): self.mount() cmd = nfs_primarystorage_plugin.CreateRootVolumeFromTemplateCmd() cmd.installUrl = '/tmp/test1.qcow2' cmd.templatePathInCache = "/tmp/test.qcow2" cmd.timeout = 30 url = aliyunagent._build_url_for_test( [nfs_primarystorage_plugin.CREATE_VOLUME_FROM_TEMPLATE_PATH]) rsp = http.json_dump_post(url, cmd, headers={ http.TASK_UUID: uuidhelper.uuid(), http.CALLBACK_URI: self.CALLBACK_URL }) time.sleep(10) self.service.stop() linux.umount_by_url(self.NFS_URL)
def test_apply_rules(self): url = aliyunagent._build_url_for_test([securitygroup_plugin.SecurityGroupPlugin.SECURITY_GROUP_APPLY_RULE_PATH]) sto = securitygroup_plugin.SecurityGroupRuleTO() sto.vmNicInternalName = 'v1.0' rto = securitygroup_plugin.RuleTO() rto.allowedCidr = '192.168.100.1/24' rto.allowedInternalIpRange = ['10.1.1.1-10.1.1.10', '10.1.1.111'] rto.endPort = 100 rto.startPort = 20 rto.protocol = securitygroup_plugin.SecurityGroupPlugin.PROTOCOL_TCP rto.type = securitygroup_plugin.SecurityGroupPlugin.RULE_TYPE_INGRESS sto.rules.append(rto) rto = securitygroup_plugin.RuleTO() rto.allowedCidr = '0.0.0.0/0' rto.allowedInternalIpRange = ['10.1.1.1-10.1.1.10', '10.1.1.111'] rto.endPort = 55 rto.startPort = 1 rto.protocol = securitygroup_plugin.SecurityGroupPlugin.PROTOCOL_UDP rto.type = securitygroup_plugin.SecurityGroupPlugin.RULE_TYPE_EGRESS sto.rules.append(rto) rto = securitygroup_plugin.RuleTO() rto.allowedCidr = '1.1.1.1/24' rto.allowedInternalIpRange = ['10.1.1.1-10.1.1.10', '10.1.1.111'] rto.endPort = -1 rto.startPort = -1 rto.protocol = securitygroup_plugin.SecurityGroupPlugin.PROTOCOL_ICMP rto.type = securitygroup_plugin.SecurityGroupPlugin.RULE_TYPE_INGRESS sto.rules.append(rto) cmd = securitygroup_plugin.ApplySecurityGroupRuleCmd() cmd.ruleTOs.append(sto) logger.debug('calling %s' % url) rsp = http.json_dump_post(url, cmd, headers={http.TASK_UUID:uuidhelper.uuid(), http.CALLBACK_URI:self.CALLBACK_URL}) time.sleep(1) self.service.stop()
def test_connect(self): url = aliyunagent._build_url_for_test([host_plugin.CONNECT_PATH]) logger.debug('calling %s' % url) ret = http.json_dump_post(url, body=ConnectCmd()) rsp = jsonobject.loads(ret) self.assertTrue(rsp.success)