Scalr\Tests\Service\CloudStack\CloudStackTest::testFunctionalCloudStack PHP Метод

testFunctionalCloudStack() публичный Метод

public testFunctionalCloudStack ( $platform, $cloudLocation, $templateId, $serviceId )
    public function testFunctionalCloudStack($platform, $cloudLocation, $templateId, $serviceId)
    {
        if ($platform === self::EMPTY_CONFIG) {
            $this->markTestSkipped();
        }
        /* @var $cs CloudStack */
        if ($this->getContainer()->environment->isPlatformEnabled($platform)) {
            $cs = $this->getContainer()->cloudstack($platform);
            //             $rs->setDebug();
            $this->assertInstanceOf($this->getCloudStackClassName('CloudStack'), $cs);
        } else {
            //Environment has not been activated yet.
            $this->markTestSkipped(sprintf('Environment for the "%s" platform has not been activated.', $platform));
        }
        $networks = $cs->network->describe();
        $this->assertNotEmpty($networks);
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\Network\\DataType\\NetworkResponseList', $networks);
        foreach ($networks as $network) {
            $this->assertNotNull($network->id);
            $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\Network\\DataType\\NetworkResponseData', $network);
            if (!empty($network->service)) {
                $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\Network\\DataType\\NetworkResponseServiceList', $network->service);
                foreach ($network->service as $service) {
                    $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\Network\\DataType\\NetworkResponseServiceData', $service);
                    $this->assertNotEmpty($service->name);
                }
            }
            if (!empty($network->tags)) {
                $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\ResponseTagsList', $network->tags);
                foreach ($network->tags as $tag) {
                    $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\ResponseTagsData', $tag);
                }
            }
        }
        $snapshots = $cs->snapshot->describe();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\Snapshot\\DataType\\SnapshotResponseList', $snapshots);
        $volumes = $cs->volume->describe(array('listall' => true));
        $ips = $cs->listPublicIpAddresses();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\IpAddressResponseList', $ips);
        $balancers = $cs->balancer->listRules();
        $ipRules = $cs->firewall->listIpForwardingRules();
        $portRules = $cs->firewall->listPortForwardingRules();
        $isos = $cs->iso->describe();
        $securityGroups = $cs->securityGroup->describe();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\SecurityGroupList', $securityGroups);
        $sshKeyPairs = $cs->sshKeyPair->describe();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\SshKeyPair\\DataType\\SshKeyResponseList', $sshKeyPairs);
        $vmGroups = $cs->vmGroup->describe();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\VmGroup\\DataType\\InstanceGroupList', $vmGroups);
        $accounts = $cs->listAccounts(array('listall' => true));
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\AccountList', $accounts);
        $jobs = $cs->listAsyncJobs(array('listall' => true));
        $capabilities = $cs->listCapabilities();
        $events = $cs->listEvents(array('listall' => true));
        $osTypes = $cs->listOsTypes();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\OsTypeList', $osTypes);
        $hypervisors = $cs->listHypervisors();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\HypervisorsList', $hypervisors);
        $limits = $cs->listResourceLimits(array('listall' => true));
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\ResourceLimitList', $limits);
        $serviceOfferings = $cs->listServiceOfferings();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\ServiceOfferingList', $serviceOfferings);
        $templates = $cs->template->describe(array('templatefilter' => "featured", "listall" => true));
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\TemplateResponseList', $templates);
        $zones = $cs->zone->describe();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\Zone\\DataType\\ZoneList', $zones);
        $zoneId = $cloudLocation;
        $diskOfferings = $cs->listDiskOfferings();
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\DiskOfferingList', $diskOfferings);
        $testName = self::getTestName('test_vm');
        $virtuals = $cs->instance->describe();
        if (count($virtuals) > 0) {
            foreach ($virtuals as $virtual) {
                if ($virtual->jobstatus !== 0 && $testName == $virtual->displayname && 'Destroyed' != $virtual->state) {
                    $responseData = $cs->instance->destroy($virtual->id);
                    $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\VirtualMachineInstancesData', $responseData);
                    $sleep = 0;
                    do {
                        sleep(10);
                        $sleep += 10;
                        $jobstatus = $cs->queryAsyncJobResult($responseData->jobid);
                    } while ($jobstatus->jobstatus != 1 && $sleep <= 300);
                }
            }
        }
        $vResult = $cs->instance->deploy(array('serviceofferingid' => $serviceId, 'templateid' => $templateId, 'zoneid' => $zoneId, 'displayname' => $testName));
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\VirtualMachineInstancesData', $vResult);
        $sleep = 0;
        do {
            sleep(10);
            $sleep += 10;
            $jobstatus = $cs->queryAsyncJobResult($vResult->jobid);
        } while ($jobstatus->jobstatus != 1 && $sleep <= 600);
        $this->assertEquals(1, $jobstatus->jobstatus);
        $listKeys = $cs->sshKeyPair->describe(array('listall' => true));
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\SshKeyPair\\DataType\\SshKeyResponseList', $listKeys);
        if (count($listKeys) > 0) {
            foreach ($listKeys as $key) {
                if ($key->name == "SCALR-ROLESBUILDER-" . SCALR_ID) {
                    $cs->sshKeyPair->delete(array('name' => $key->name));
                }
            }
        }
        $keyPair = $cs->sshKeyPair->create(array('name' => "SCALR-ROLESBUILDER-" . SCALR_ID));
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\SshKeyPair\\DataType\\SshPrivateKeyResponseData', $keyPair);
        $this->assertNotEmpty($keyPair->privatekey);
        $listKeys = $cs->sshKeyPair->describe(array('listall' => true));
        $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\SshKeyPair\\DataType\\SshKeyResponseList', $listKeys);
        if (count($listKeys) > 0) {
            foreach ($listKeys as $key) {
                if ($key->name == "SCALR-ROLESBUILDER-" . SCALR_ID) {
                    $cs->sshKeyPair->delete(array('name' => $key->name));
                }
            }
        }
        $requestObject = new AssociateIpAddressData();
        $requestObject->zoneid = $zoneId;
        $ipResult = $cs->associateIpAddress($requestObject);
        $this->assertNotEmpty($ipResult->id);
        $sleep = 0;
        do {
            $sleep += 20;
            $job = $cs->queryAsyncJobResult($ipResult->jobid);
            sleep(20);
        } while ($job->jobstatus != 1 && $sleep <= 400);
        $this->assertEquals(1, $job->jobstatus);
        $ipInfo = $cs->listPublicIpAddresses(array('id' => $ipResult->id));
        $this->assertNotNull($ipInfo);
        $this->assertEquals($ipResult->id, $ipInfo[0]->id);
        $virtuals = $cs->instance->describe();
        if (count($virtuals) > 0) {
            foreach ($virtuals as $virtual) {
                if ($virtual->jobstatus !== 0 && $testName == $virtual->displayname && 'Destroyed' != $virtual->state) {
                    $resultRule = $cs->firewall->createPortForwardingRule(array('ipaddressid' => $ipResult->id, 'privateport' => 8014, 'protocol' => "udp", 'publicport' => 30002, 'virtualmachineid' => $virtual->id));
                    $this->assertInstanceOf('Scalr\\Service\\CloudStack\\Services\\Firewall\\DataType\\ForwardingRuleResponseData', $resultRule);
                    $cs->firewall->deletePortForwardingRule($resultRule->id);
                    $result = $cs->disassociateIpAddress($ipResult->id);
                    $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\ResponseDeleteData', $result);
                    $responseData = $cs->instance->destroy($virtual->id);
                    $this->assertInstanceOf('Scalr\\Service\\CloudStack\\DataType\\VirtualMachineInstancesData', $responseData);
                    $sleep = 0;
                    do {
                        $sleep += 10;
                        $jobstatus = $cs->queryAsyncJobResult($responseData->jobid);
                        sleep(10);
                    } while ($jobstatus->jobstatus != 1 && $sleep <= 300);
                }
            }
        }
    }