/** * Creates a new DB subnet group. * DB subnet groups must contain at least one subnet in at least two AZs in the region. * * @param CreateDBSubnetGroupRequestData $request * @return DBSubnetGroupData * @throws RdsException */ public function createDBSubnetGroup(CreateDBSubnetGroupRequestData $request) { $result = null; $options = $request->getQueryArray(); if ($this->rds->getApiClientType() === Aws::CLIENT_SOAP) { if (isset($options['SubnetIds.member.1'])) { foreach ($options as $k => $v) { if (strpos($k, 'SubnetIds.member.') !== false) { $options['SubnetIds']['SubnetId'][] = $v; unset($options[$k]); } } } } $response = $this->client->call(ucfirst(__FUNCTION__), $options); if ($response->getError() === false) { $sxml = simplexml_load_string($response->getRawContent()); if (!$this->exist($sxml->CreateDBSubnetGroupResult)) { throw new RdsException(sprintf(self::UNEXPECTED, 'create DBSubnet group')); } $result = $this->_loadDBSubnetGroupData($sxml->CreateDBSubnetGroupResult->DBSubnetGroup); } return $result; }
/** * @test */ public function testClustersFunctional() { $this->skipIfEc2PlatformDisabled(); $this->deleteClusterObjects(); $aws = $this->getEnvironment()->aws(AwsTestCase::REGION); $masterUserPassword = substr(uniqid(), 0, 10); $dbClusterId = self::getTestName(self::NAME_INSTANCE); $subnets = $aws->ec2->subnet->describe(); $subnetIds = []; $zones = []; $vpcId = null; foreach ($subnets as $subnet) { /* @var $subnet SubnetData */ if (empty($vpcId)) { $vpcId = $subnet->vpcId; } if (!in_array($subnet->availabilityZone, $zones) && $subnet->vpcId == $vpcId) { $zones[] = $subnet->availabilityZone; $subnetIds[] = $subnet->subnetId; } if (count($subnetIds) > 1) { break; } } $groupName = self::getTestName('subnetname'); $requestSubnet = new CreateDBSubnetGroupRequestData('test', $groupName); $requestSubnet->setSubnetIds($subnetIds); $subnetGroup = $aws->rds->dbSubnetGroup->create($requestSubnet); $this->assertEquals($subnetGroup->dBSubnetGroupName, $groupName); $request = new CreateDBClusterRequestData($dbClusterId, 'aurora', 'phpunituser', (string) $masterUserPassword ?: null); $request->dBSubnetGroupName = $subnetGroup->dBSubnetGroupName; $dbClusterData = $aws->rds->dbCluster->create($request); $this->assertInstanceOf($this->getRdsClassName('DataType\\DBClusterData'), $dbClusterData); $this->assertEquals($dbClusterData->dBClusterIdentifier, $dbClusterId); $timeout = 0; while ($dbClusterData->status != DBClusterData::STATUS_AVAILABLE && ($timeout += static::SLEEP_TIMEOUT) < static::SLEEP_TIME) { sleep(static::SLEEP_TIMEOUT); $dbClusterData = $dbClusterData->refresh(); } $this->assertEquals(DBClusterData::STATUS_AVAILABLE, $dbClusterData->status); $snapId = self::getTestName(self::NAME_DB_SNAPSHOT); $clusterSnapshot = $aws->rds->dbClusterSnapshot->create($dbClusterId, $snapId); $this->assertInstanceOf($this->getRdsClassName('DataType\\DBClusterSnapshotData'), $clusterSnapshot); $this->assertEquals($clusterSnapshot->dBClusterIdentifier, $dbClusterId); $this->assertEquals($clusterSnapshot->dBClusterSnapshotIdentifier, $snapId); $timeout = 0; while ($clusterSnapshot->status !== DBClusterSnapshotData::STATUS_AVAILABLE && ($timeout += static::SLEEP_TIMEOUT) < static::SLEEP_TIME) { sleep(static::SLEEP_TIMEOUT); $clusterSnapshot = $aws->rds->dbClusterSnapshot->describe($dbClusterId, $snapId)->get(); } $this->assertEquals(DBClusterSnapshotData::STATUS_AVAILABLE, $clusterSnapshot->status); $this->deleteClusterObjects(); }