Skip to content
Snippets Groups Projects
Commit 0ec5a477 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3010193 by Xiaohua Guan, yas, baldwinlouie: Randomize the test data...

Issue #3010193 by Xiaohua Guan, yas, baldwinlouie: Randomize the test data (YAML properties) in test cases
parent a1c167f7
No related branches found
Tags 4.0.1
No related merge requests found
Showing
with 437 additions and 817 deletions
AllocateAddress:
PublicIp: 10.0.0.0
PublicIp: {{public_ip}}
CreateImage:
ImageId: dummy image
ImageId: {{image_id}}
DescribeInstances:
Reservations:
- Instances: []
OwnerId: 123456789012
ReservationId: r-1234567890abcdef0
OwnerId: {{owner_id}}
ReservationId: {{reservation_id}}
TerminateInstances:
TerminatingInstances:
- InstanceId: {{instance_id}}
#@FIXME move to Reservations area.
InstanceId: '$name'
InstanceId: '{{instance_id}}'
InstanceType: t2.micro
Placement:
AvailabilityZone: us-west-1c
Tenancy: default
GroupName: ''
HostId: host1
Affinity: affinity1
LaunchTime: '2018-01-01T00:00:00.000Z'
GroupName: {{group_name}}
HostId: {{host_id}}
Affinity: {{affinity}}
LaunchTime: '{{launch_time}}'
Tags:
- Key: Name
Value: '$name'
Value: '{{name}}'
SecurityGroups:
- GroupId: sg-e4076980
GroupName: SecurityGroup1
- GroupId: {{security_group_id}}
GroupName: {{security_group_name}}
State:
Code: 16
Name: running
PublicDnsName: ec2-54-250-160-22.ap-northeast-1.compute.amazonaws.com
PublicIpAddress: 54.250.160.22
PrivateDnsName: ip-172-20-61-130.ap-northeast-1.compute.internal
PrivateIpAddress: 172.20.61.130
KeyName: '$keypair'
PublicDnsName: {{public_dns_name}}
PublicIpAddress: {{public_ip_address}}
PrivateDnsName: {{private_dns_name}}
PrivateIpAddress: {{private_ip_address}}
KeyName: '{{key_name}}'
Monitoring:
State: enabled
VpcId: vpc-e867158c
SubnetId: subnet-0b1b1a7d
VpcId: {{vpc_id}}
SubnetId: {{subnet_id}}
SourceDestCheck: false
EbsOptimized: false
RootDeviceType: ebs
RootDeviceName: /dev/xvda
ImageId: ami-f46f5993
ImageId: {{image_id}}
VirtualizationType: hvm
AmiLaunchIndex: 0
StateTransitionReason: ''
StateTransitionReason: '{{reason}}'
CreateKeyPair:
KeyName: dummy key
KeyFingerprint: dummy fingerprint
KeyName: {{key_name}}
KeyFingerprint: '{{key_fingerprint}}'
KeyMaterial: '{{key_material}}'
CreateNetworkInterface:
NetworkInterfaceId: dummy network interface
NetworkInterfaceId: {{network_interface_id}}
Status: pending
VpcId: dummy vpc id
VpcId: {{vpc_id}}
DescribeVpcs:
Vpcs:
VpcId: vpc-1a2b3c4d
CidrBlock: 192.168.0.0/16
VpcId: {{vpc_id}}
CidrBlock: {{cidr_block}}
CreateSecurityGroup:
GroupId: dummy group
GroupId: {{group_id}}
CreateSnapshot:
SnapshotId: dummy snapshot
SnapshotId: {{snapshot_id}}
Status: pending
StartTime: '2018-01-01T00:00:00.000Z'
StartTime: '{{start_time}}'
Encrypted: TRUE
CreateVolume:
VolumeId: dummy volume
CreateTime: '2018-01-01T00:00:00.000Z'
VolumeId: {{volume_id}}
CreateTime: '{{create_time}}'
State: creating
<?php
use Drupal\simpletest\WebTestBase;
namespace Drupal\Tests\aws_cloud\Functional\Config;
/**
*
*/
class ConfigTestCase extends WebTestBase {
protected $profile = 'standard';
protected $userList = [];
protected $privileged_user;
/**
*
*/
public function setUp() {
parent::setUp('cloud', 'cloud_server_templates', 'cloud_scripting', 'cloud_pricing', 'cloud_alerts', 'cloud_activity_audit', 'cloud_cluster', 'aws_api', 'aws_lib', 'aws', 'aws_cloud');
// Create and log in our privileged user with the basic permissions.
$this->privileged_user = $this->drupalCreateUser([
'access administration pages',
'administer site configuration',
'administer cloud',
'access dashboard',
'access audit report',
'copy server template',
'create server template',
'delete server template',
'edit server template',
'launch server template',
'list server templates',
'set scripts and alerts',
'view server template',
'list alerts',
'create alert',
'view alerts',
'edit alert',
'delete alert',
'create cluster',
'delete cluster',
'list clusters',
'update cluster',
'create script',
'list scripts',
'edit script',
'delete script',
'create pricing',
'list pricing',
'edit pricing',
'delete pricing',
]);
$this->userList[] = $this->privileged_user->name;
$this->drupalLogin($this->privileged_user);
$this->configure();
}
/**
*
*/
public function configure() {
// Setup some sub-clouds in the system.
foreach ($this->data as $key => $value) {
$this->drupalPost('admin/settings/clouds/add', $value, t('Create'));
$this->assertText(t('Cloud @cloud_name has been created', [
'@cloud_name' => $value['cloud_name'],
]), 'Confirm Message: The cloud has been created');
}
// Reset the cached modules, permissions...etc.
$this->resetAll();
// Create a new user with permissions against the
// newly enabled sub-clouds.
$this->privileged_user = $this->drupalCreateUser([
'access administration pages',
'administer site configuration',
'administer cloud',
'access dashboard',
'access audit report',
'copy server template',
'create server template',
'delete server template',
'edit server template',
'launch server template',
'list server templates',
'set scripts and alerts',
'view server template',
'list alerts',
'create alert',
'view alerts',
'edit alert',
'delete alert',
'create cluster',
'delete cluster',
'list clusters',
'update cluster',
'create script',
'list scripts',
'edit script',
'delete script',
'create pricing',
'list pricing',
'edit pricing',
'delete pricing',
// Amazon sub-cloud.
'amazon_ec2 administer cloud',
'amazon_ec2 list instances',
'amazon_ec2 launch instance',
'amazon_ec2 terminate all instances',
'amazon_ec2 terminate own instance',
'amazon_ec2 access all console',
'amazon_ec2 access own console',
'amazon_ec2 list images',
'amazon_ec2 register image',
'amazon_ec2 delete image',
'amazon_ec2 list key fingerprints',
'amazon_ec2 list key names',
'amazon_ec2 register key',
'amazon_ec2 update key',
'amazon_ec2 delete key',
'amazon_ec2 list IPs',
'amazon_ec2 add IP',
'amazon_ec2 delete IP',
'amazon_ec2 assign IP',
'amazon_ec2 update instance details',
'amazon_ec2 list security group',
'amazon_ec2 register security group',
'amazon_ec2 setup security group',
'amazon_ec2 delete security group',
'amazon_ec2 list volume',
'amazon_ec2 create volume',
'amazon_ec2 delete volume',
'amazon_ec2 attach volume',
'amazon_ec2 detach volume',
'amazon_ec2 list snapshot',
'amazon_ec2 create snapshot',
'amazon_ec2 delete snapshot',
'amazon_ec2 display cpu load',
'amazon_ec2 display traffic amount',
'amazon_ec2 display storage space',
'amazon_ec2 list template',
'amazon_ec2 create template',
'amazon_ec2 update template',
'amazon_ec2 update own template',
'amazon_ec2 delete template',
'amazon_ec2 delete own template',
'amazon_ec2 copy template',
'amazon_ec2 access report',
'access audit report',
'copy server template',
'create server template',
'delete server template',
'edit server template',
'launch server template',
'list server templates',
'set scripts and alerts',
'view server template',
]);
$this->userList[] = $this->privileged_user->name;
$this->drupalLogin($this->privileged_user);
}
/**
* Tear Down function.
*/
public function tearDown() {
foreach ($this->userList as $name) {
$this->tearDownSSHKey($name);
}
$this->tearDownSSHKEy($this->privileged_user->name);
parent::tearDown();
}
/**
* Data definition for test keys
* For each new sub cloud, add its access variables.
*/
private $data = [
'amazon_ec2' => [
'cloud_name' => 'amazon_ec2',
'base_cloud' => 'amazon',
'cloud_display_name' => 'Amazon EC2',
'api_version' => AMAZON_EC2_API_VERSION,
'host_uri' => AMAZON_EC2_HOST_URI,
'aws_access_key' => AMAZON_EC2_AWS_ACCESS_KEY,
'aws_secret_key' => AMAZON_EC2_API_SECRET_KEY,
'user_id' => AMAZON_EC2_USER_ID,
'image_upload_url' => AMAZON_S3_IMAGE_UPLOAD_URI,
'image_register_url' => AMAZON_EC2_IMAGE_REGISTER_URI,
'certificate' => AMAZON_EC2_X509_CERTIFICATE ,
],
];
/**
* Test ssh key deletion.
*/
protected function tearDownSSHKey($key_name = '') {
$clouds = $this->getClouds();
foreach ($clouds as $cloud) {
$this->deleteSSHKey($key_name, $cloud);
$this->assertText(t('Key Pair deleted successfully: @keyname', [
'@keyname' => $key_name,
]), t('Confirmed: Key Pair deleted successfully: @keyname', [
'@keyname' => $key_name,
]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
}
}
/**
* Helper function to refresh a subcloud page.
*/
protected function refreshInstances($cloud) {
$this->drupalGet('clouds/' . $cloud . '/get_instances_data', [
'query' => [
'destination' => 'clouds/' . $cloud . '/instances',
],
]);
}
/**
* Helper function to refresh an images listing page.
*/
protected function refreshImages($cloud) {
$this->drupalGet('clouds/' . $cloud . '/getimagedata', [
'query' => [
'destination' => 'clouds/' . $cloud . '/images',
],
]);
}
/**
* Helper function to refresh a security group listing page.
*/
protected function refreshSecurityGroups($cloud) {
$this->drupalGet('clouds/' . $cloud . '/get_security_group_data');
}
/**
* Helper function to refresh ssh keys.
*/
protected function refreshSSHKeys($cloud) {
$this->drupalGet('clouds/' . $cloud . '/get_ssh_keys_data');
}
/**
* Helper function to refresh Elastic IP.
*/
protected function refreshElasticIP($cloud) {
$this->drupalGet('clouds/' . $cloud . '/get_elastic_ips_data');
}
/**
* Helper function to refresh Volumes.
*/
protected function refreshVolumes($cloud) {
$this->drupalGet('clouds/' . $cloud . '/get_volumes_data');
}
/**
* Helper function to refresh snapshots.
*/
protected function refreshSnapshots($cloud) {
$this->drupalGet('clouds/' . $cloud . '/get_snapshots_data');
}
/**
* Helper function to get the cloud names in the database.
* Using the cloud name, we can then run all the tests.
* This function will change after multi region gets
* implemented.
*/
protected function getClouds() {
$clouds = [];
$query = db_query("select cloud_name from {cloud_clouds}");
while ($result = db_result($query)) {
$clouds[] = $result;
}
return $clouds;
}
/**
* Function returns an IP address from the {cloud_aws_elastic_ip} table.
*/
protected function getIp($cloud) {
return db_result(db_query("select public_ip from {cloud_aws_elastic_ip} where cloud_type='%s' and public_ip_name = '%s'", [
$cloud,
'- changeme -',
]));
}
/**
* Function finds a Volume by Nickname.
*/
protected function getVolumeId($nickname, $cloud) {
return db_result(db_query("select volume_id from {cloud_aws_ebs_volumes} where nickname = '%s' and cloud_type = '%s'", [
'SimpleTest_Volume',
$cloud,
]));
}
/**
* Helper function to create ssh keys.
*/
protected function createSSHKey($key_name, $cloud) {
$edit = [
'keyname_text' => $key_name,
'cloud_context' => $cloud,
];
$this->drupalPost('clouds/' . $cloud . '/ssh_keys/create', $edit, t('Create'));
}
/**
* Helper function to delete ssh keys.
*/
protected function deleteSSHKey($key_name, $cloud) {
$this->drupalGet('clouds/' . $cloud . '/ssh_keys/delete', [
'query' => [
'key_name' => $key_name,
],
]);
}
/**
* Helper function to refresh the clouds page.
*/
protected function refreshPageAll() {
$this->drupalGet('clouds/getdata', ['query' => ['src' => 'clouds']]);
}
}
......@@ -94,7 +94,7 @@ abstract class AwsCloudTestCase extends BrowserTestBase {
private function initMockData() {
$mock_data = [];
foreach ([__CLASS__, get_class($this)] as $class_name) {
$content = $this->getMockDataFileContent($class_name);
$content = $this->getMockDataFileContent($class_name, $this->getMockDataTemplateVars());
if (!empty($content)) {
$mock_data = array_merge($mock_data, Yaml::decode($content));
}
......@@ -106,13 +106,29 @@ abstract class AwsCloudTestCase extends BrowserTestBase {
->save();
}
protected function getMockDataFileContent($class_name, $suffix = '') {
protected function getMockDataFileContent($class_name, $vars, $suffix = '') {
$path = drupal_realpath(drupal_get_path('module', 'aws_cloud')) . '/tests/mock_data';
$pos = strpos($class_name, 'aws_cloud') + strlen('aws_cloud');
$path .= str_replace('\\', '/', substr($class_name, $pos)) . $suffix . '.yml';
if (!file_exists($path)) {
return '';
}
return file_get_contents($path);
$twig = \Drupal::service('twig');
return $twig->renderInline(file_get_contents($path), $vars);
}
protected function getMockDataTemplateVars() {
return [];
}
protected function reloadMockData() {
$mock_data = $this->getMockDataFromConfig();
$file_content = $this->getMockDataFileContent(get_class($this), $this->getMockDataTemplateVars());
if (!empty($file_content)) {
$mock_data = array_merge($mock_data, Yaml::decode($file_content));
}
$this->updateMockDataToConfig($mock_data);
}
}
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\aws_cloud\Functional\Ec2;
use Drupal\Component\Utility\Random;
use Drupal\Tests\aws_cloud\Functional\Utils;
// Updated by yas 2016/06/23
// Updated by yas 2016/06/02
......@@ -30,6 +31,12 @@ class ElasticIpTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
return [
'public_ip' => Utils::getRandomPublicIp(),
];
}
/**
* Tests CRUD for Elastic IP information.
*/
......@@ -47,6 +54,7 @@ class ElasticIpTest extends AwsCloudTestCase {
// Add a new Elastic IP.
$add = $this->createElasticIpTestData();
for ($i = 0; $i < AWS_CLOUD_ELASTIC_IP_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$num = $i + 1;
......@@ -59,8 +67,8 @@ class ElasticIpTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Add | Make sure w/o Warnings'));
$this->assertText($add[$i]['name'], t('Elastic IP: @name ', ['@name' => $add[$i]['name']]));
$this->assertText(t('The AWS Cloud Elastic IP "@name', [
'@name' => $add[$i]['name'],
]),
'@name' => $add[$i]['name'],
]),
t('Confirm Message') . ': '
. t('The AWS Cloud Elastic IP "@name" has been created.', [
'@name' => $add[$i]['name'],
......@@ -142,53 +150,32 @@ class ElasticIpTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('Name: @name ', ['@name' => $edit[$i]['name']]));
$this->assertText(t('The AWS Cloud Elastic IP "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Elastic IP "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]));
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Elastic IP "@name" has been deleted.', [
'@name' => $edit[$i]['name']])
);
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/elastic_ip");
$this->assertResponse(200, t('Delete | List | HTTP 200: Elastic IP #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
/*
for ($j = 0; $j < $i + 1; $j++) {
$this->assertNoText($edit[$j]['name'],
t('Delete | List | Make sure w/ Listing: @name', array(
'@name' => $edit[$j]['name'])));
$this->assertNoText($edit[$j]['name'],
t('Delete | List | Make sure w/ Listing: @name', array(
'@name' => $edit[$j]['name']))
);
}
*/
}
// Filtering scripting information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/clouds/aws_cloud/$cloud_context/elastic_ip', $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$scripting_id = AWS_CLOUD_ELASTIC_IP_REPEAT_COUNT - 1 ;
$this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
*/
// end
// } // End of foreach.
}
/**
*
*/
private function createElasticIpTestData() {
$this->random = new Random();
$data = [];
// 3 times.
for ($i = 0; $i < AWS_CLOUD_ELASTIC_IP_REPEAT_COUNT; $i++) {
......
......@@ -27,6 +27,12 @@ class ImageTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
return [
'image_id' => 'ami-' . $this->random->name(8, TRUE),
];
}
/**
* Tests CRUD for image information.
*/
......@@ -43,7 +49,7 @@ class ImageTest extends AwsCloudTestCase {
$add = $this->createImageTestData();
// 3 times.
for ($i = 0; $i < AWS_CLOUD_IMAGE_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$num = $i + 1;
$this->drupalPostForm("/clouds/aws_cloud/$cloud_context/image/add",
......@@ -134,50 +140,30 @@ class ImageTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('Name: @name ', ['@name' => $edit[$i]['name']]));
$this->assertText(t('The AWS Cloud Image "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Image "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]));
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Image "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/image");
$this->assertResponse(200, t('Delete | List | HTTP 200: Image #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
/*
for ($j = 0; $j < $i + 1; $j++) { // 3 times
$this->assertNoText($edit[$i]['name'],
t('Delete | List | Make sure w/ Listing: @name', array(
'@name' => $edit[$i]['name'])));
$this->assertNoText($edit[$i]['name'],
t('Delete | List | Make sure w/ Listing: @name', array(
'@name' => $edit[$i]['name'])));
}
*/
}
// Filtering scripting information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/clouds/aws_cloud/$cloud_context/image', $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$scripting_id = AWS_CLOUD_IMAGE_REPEAT_COUNT - 1 ;
$this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
*/
// end
// } // End of foreach.
}
/**
*
*/
private function createImageTestData() {
$this->random = new Random();
$data = [];
for ($i = 0; $i < AWS_CLOUD_IMAGE_REPEAT_COUNT; $i++) {
......
......@@ -16,8 +16,9 @@ namespace Drupal\Tests\aws_cloud\Functional\Ec2;
use Drupal\Component\Utility\Random;
use Drupal\Component\Serialization\Yaml;
use Drupal\Tests\aws_cloud\Functional\Utils;
define('AWS_CLOUD_INSTANCE_REPEAT_COUNT', 3);
define('AWS_CLOUD_CONFIG_REPEAT_COUNT', 1);
/**
* Tests AWS Cloud Instance.
......@@ -38,6 +39,33 @@ class InstanceTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
$public_ip = Utils::getRandomPublicIp();
$private_ip = Utils::getRandomPrivateIp();
$regions = ['us-west-1', 'us-west-2'];
$region = $regions[array_rand($regions)];
return [
'owner_id' => rand(100000000000, 999999999999), //12 digits
'reservation_id' => 'r-' . $this->random->name(17, TRUE),
'group_name' => $this->random->name(8, TRUE),
'host_id' => $this->random->name(8, TRUE),
'affinity' => $this->random->name(8, TRUE),
'launch_time' => date('c'),
'security_group_id' => 'sg-' . $this->random->name(8, TRUE),
'security_group_name' => $this->random->name(10, TRUE),
'public_dns_name' => Utils::getPublicDns($region, $public_ip),
'public_ip_address' => $public_ip,
'private_dns_name' => Utils::getPrivateDns($region, $private_ip),
'private_ip_address' => $private_ip,
'vpc_id' => 'vpc-' . $this->random->name(8, TRUE),
'subnet_id' => 'subnet-' . $this->random->name(8, TRUE),
'image_id' => 'ami-' . $this->random->name(8, TRUE),
'reason' => $this->random->string(16, TRUE),
'instance_id' => 'i-' . $this->random->name(17, TRUE),
];
}
/**
* Tests CRUD for instance information.
*/
......@@ -70,14 +98,6 @@ class InstanceTest extends AwsCloudTestCase {
'@name' => $add[$j]['name'],
]));
}
// Make sure View.
/*
$this->drupalGet("/clouds/aws_cloud/$cloud_context/instance/$num");
$this->assertResponse(200, t('Launch | View | HTTP 200: Instance #@num', array('@num' => $num)));
$this->assertNoText(t('Notice'), t('Launch | View | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Launch | View | Make sure w/o Warnings'));
*/
}
// Edit an Instance information.
......@@ -99,17 +119,18 @@ class InstanceTest extends AwsCloudTestCase {
unset($edit[$i]['ramdisk_id']);
unset($edit[$i]['user_data']);
// @FIXME - $num => $instance_id
$this->drupalPostForm("/clouds/aws_cloud/$cloud_context/instance/$num/edit",
$edit[$i],
t('Save'));
$this->updateInstanceInMockData($num - 1, $edit[$i]['name']);
$this->assertResponse(200, t('Edit | HTTP 200: A New Instance #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Edit | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Edit | Make sure w/o Warnings'));
$this->assertText(t('The AWS Cloud Instance "@name" has been saved.', [
'@name' => $edit[$i]['name'],
]),
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Edit | The AWS Cloud Instance "@name" has been saved.', [
'@name' => $edit[$i]['name'],
......@@ -120,8 +141,8 @@ class InstanceTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Edit | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('Name: @name ', ['@name' => $edit[$i]['name']]));
$this->assertText(t('The AWS Cloud Instance "@name" has been saved.', [
'@name' => $edit[$i]['name'],
]),
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Edit | The AWS Cloud Instance "@name" has been saved.', [
'@name' => $edit[$i]['name'],
......@@ -139,70 +160,55 @@ class InstanceTest extends AwsCloudTestCase {
]));
}
}
//
// // Terminate Instance.
// for ($i = 0; $i < AWS_CLOUD_INSTANCE_REPEAT_COUNT; $i++) {
//
// $num = $i + 1;
//
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/instance/$num/terminate");
// $this->assertResponse(200, t('Terminate: HTTP 200: Instance #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Terminate | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Terminate | Make sure w/o Warnings'));
// $this->drupalPostForm("/clouds/aws_cloud/$cloud_context/instance/$num/terminate",
// [],
// t('Delete | Terminate'));
//
// $this->assertResponse(200, t('Terminate | HTTP 200: The Cloud Instance #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Terminate | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Terminate | Make sure w/o Warnings'));
// $this->assertText($edit[$i]['name'], t('Instance Name: @name ', ['@name' => $edit[$i]['name']]));
// $this->assertText(t('The AWS Cloud Instance "@name" has been terminated.', [
// '@name' => $edit[$i]['name'],
// ]),
// t('Confirm Message') . ': '
// . t('Terminate | The AWS Cloud Instance "@name" has been terminated.', [
// '@name' => $edit[$i]['name'],
// ]));
//
// // Make sure listing.
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/instance");
// $this->assertResponse(200, t('Terminate | HTTP 200: Instance #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Terminate | List | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Terminate | List | Make sure w/o Warnings'));
// /*
// for ($j = 0; $j < $i + 1; $j++) { // 3 times
// $this->assertNoText($edit[$i]['name'],
// t('Terminate | List | Make sure w/ Listing: @name', array(
// '@name' => $edit[$i]['name'])));
// }
// */
// }
//
// // Filtering scripting information item
// /*
// $filter = array(
// 'filter' => 't1',
// 'operation' => 0,
// );
//
// $this->drupalPost("/clouds/aws_cloud/$cloud_context/instance', $filter, t('Apply'));
// $this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
// $scripting_id = AWS_CLOUD_INSTANCE_REPEAT_COUNT - 1 ;
// $this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
// $this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
// $this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
// */
// // end
// // } // End of foreach.
$options = ['query' => ['destination' => "/clouds/aws_cloud/$cloud_context/instance"]];
// Terminate Instance.
for ($i = 0; $i < AWS_CLOUD_INSTANCE_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->drupalGet("/clouds/aws_cloud/$cloud_context/instance/$num/terminate");
$this->assertResponse(200, t('Terminate: HTTP 200: Instance #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Terminate | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Terminate | Make sure w/o Warnings'));
$this->deleteFirstInstanceInMockData();
$this->drupalPostForm("/clouds/aws_cloud/$cloud_context/instance/$num/terminate",
[],
t('Delete | Terminate'),
$options);
$this->assertResponse(200, t('Terminate | HTTP 200: The Cloud Instance #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Terminate | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Terminate | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('Instance Name: @name ', ['@name' => $edit[$i]['name']]));
$this->assertText(t('The AWS Cloud Instance "@name" has been terminated.', [
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Terminate | The AWS Cloud Instance "@name" has been terminated.', [
'@name' => $edit[$i]['name'],
]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/instance");
$this->assertResponse(200, t('Terminate | HTTP 200: Instance #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Terminate | List | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Terminate | List | Make sure w/o Warnings'));
for ($j = 0; $j < $i + 1; $j++) { // 3 times
$this->assertNoText($edit[$i]['name'],
t('Terminate | List | Make sure w/ Listing: @name', array(
'@name' => $edit[$i]['name'])));
}
}
}
/**
*
*/
private function createInstanceTestData() {
$this->random = new Random();
$data = [];
for ($i = 0; $i < AWS_CLOUD_INSTANCE_REPEAT_COUNT; $i++) {
......@@ -212,7 +218,6 @@ class InstanceTest extends AwsCloudTestCase {
// Input Fields.
$data[$i] = [
'name' => "Instance #$num - " . date('Y/m/d - ') . $this->random->name(8, TRUE),
// 'cloud_type' => 'amazon_ec2', // already set
'image_id' => 'ami-' . $this->random->name(8, TRUE),
'min_count' => $num,
'max_count' => $num * 2,
......@@ -258,13 +263,29 @@ class InstanceTest extends AwsCloudTestCase {
$template->save();
}
private function addInstanceMockData($name, $keypair) {
private function addInstanceMockData($name, $key_pair_name) {
$mock_data = $this->getMockDataFromConfig();
$instance_mock_data_content = $this->getMockDataFileContent(get_class($this), '_instance');
$instance_mock_data_content = str_replace('$name', $name, $instance_mock_data_content);
$instance_mock_data_content = str_replace('$keypair', $keypair, $instance_mock_data_content);
$vars = $this->getMockDataTemplateVars();
$vars['name'] = $name;
$vars['key_name'] = $key_pair_name;
$instance_mock_data_content = $this->getMockDataFileContent(get_class($this), $vars, '_instance');
$instance_mock_data = Yaml::decode($instance_mock_data_content);
$mock_data['DescribeInstances']['Reservations'][0]['Instances'][] = $instance_mock_data;
$this->updateMockDataToConfig($mock_data);
}
private function deleteFirstInstanceInMockData() {
$mock_data = $this->getMockDataFromConfig();
$instances = $mock_data['DescribeInstances']['Reservations'][0]['Instances'];
array_shift($instances);
$mock_data['DescribeInstances']['Reservations'][0]['Instances'] = $instances;
$this->updateMockDataToConfig($mock_data);
}
private function updateInstanceInMockData($instance_index, $name) {
$mock_data = $this->getMockDataFromConfig();
$mock_data['DescribeInstances']['Reservations'][0]['Instances'][$instance_index]['Tags'][0]['Value'] = $name;
$this->updateMockDataToConfig($mock_data);
}
}
......@@ -30,6 +30,22 @@ class KeyPairTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
$key_fingerprint_parts = [];
for ($i = 0; $i < 20; $i++) {
$key_fingerprint_parts[] = sprintf('%02x', rand(0, 255));
}
$key_material = '---- BEGIN RSA PRIVATE KEY ----'
. $this->random->name(871, TRUE)
. '-----END RSA PRIVATE KEY-----';
return [
'key_name' => $this->random->name(15, TRUE),
'key_fingerprint' => implode(':', $key_fingerprint_parts),
'key_material' => $key_material,
];
}
/**
* Tests CRUD for Key Pair information.
*/
......@@ -45,6 +61,7 @@ class KeyPairTest extends AwsCloudTestCase {
// Add a new Key Pair.
$add = $this->createKeyPairTestData();
for ($i = 0; $i < AWS_CLOUD_KEY_PAIR_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$num = $i + 1;
......@@ -76,69 +93,51 @@ class KeyPairTest extends AwsCloudTestCase {
}
}
// // Delete Key Pair.
// for ($i = 0; $i < AWS_CLOUD_KEY_PAIR_REPEAT_COUNT; $i++) {
//
// $num = $i + 1;
//
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/key_pair/$num/delete");
// $this->assertResponse(200, t('Delete | HTTP 200: Key Pair #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->drupalPostForm("/clouds/aws_cloud/$cloud_context/key_pair/$num/delete",
// [],
// t('Delete'));
//
// $this->assertResponse(200, t('Delete | HTTP 200: The Cloud Key Pair #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->assertText($add[$i]['key_pair_name'], t('Name: @key_pair_name ', ['@key_pair_name' => $add[$i]['key_pair_name']]));
// $this->assertText(t('The AWS Cloud Key Pair "@key_pair_name" has been deleted.', [
// '@key_pair_name' => $add[$i]['key_pair_name'],
// ]),
// t('Confirm Message') . ': '
// . t('Delete | The AWS Cloud Key Pair "@key_pair_name" has been deleted.', [
// '@key_pair_name' => $add[$i]['key_pair_name'],
// ]));
//
// // Make sure listing.
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/key_pair");
// $this->assertResponse(200, t('HTTP 200: Delete | Key Pair #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
// /*
// for ($j = 0; $j < $i + 1; $j++) { // 3 times
// $this->assertNoText($add[$i]['key_pair_name'],
// t('Delete | List | Make sure w/ Listing: @key_pair_name', array(
// '@key_pair_name' => $add[$i]['key_pair_name'])));
// }
// */
// }
// Filtering scripting information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/clouds/aws_cloud/$cloud_context/key_pair', $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$scripting_id = AWS_CLOUD_KEY_PAIR_REPEAT_COUNT - 1 ;
$this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
*/
// end
// } // End of foreach.
$options = ['query' => ['destination' => "/clouds/aws_cloud/$cloud_context/key_pair"]];
// Delete Key Pair.
for ($i = 0; $i < AWS_CLOUD_KEY_PAIR_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->drupalGet("/clouds/aws_cloud/$cloud_context/key_pair/$num/delete");
$this->assertResponse(200, t('Delete | HTTP 200: Key Pair #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->drupalPostForm("/clouds/aws_cloud/$cloud_context/key_pair/$num/delete",
[],
t('Delete'),
$options);
$this->assertResponse(200, t('Delete | HTTP 200: The Cloud Key Pair #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->assertText($add[$i]['key_pair_name'], t('Name: @key_pair_name ', ['@key_pair_name' => $add[$i]['key_pair_name']]));
$this->assertText(t('The AWS Cloud Key Pair "@key_pair_name" has been deleted.', [
'@key_pair_name' => $add[$i]['key_pair_name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Key Pair "@key_pair_name" has been deleted.', [
'@key_pair_name' => $add[$i]['key_pair_name'],
]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/key_pair");
$this->assertResponse(200, t('HTTP 200: Delete | Key Pair #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
for ($j = 0; $j < $i + 1; $j++) { // 3 times
$this->assertNoText($add[$i]['key_pair_name'],
t('Delete | List | Make sure w/ Listing: @key_pair_name', array(
'@key_pair_name' => $add[$i]['key_pair_name'])));
}
}
}
/**
*
*/
private function createKeyPairTestData() {
$this->random = new Random();
$data = [];
for ($i = 0; $i < AWS_CLOUD_KEY_PAIR_REPEAT_COUNT; $i++) {
......
......@@ -32,6 +32,13 @@ class NetworkInterfaceTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
return [
'network_interface_id' => 'eni-' . $this->random->name(8, TRUE),
'vpc_id' => 'vpc-' . $this->random->name(8, TRUE),
];
}
/**
* Tests CRUD for Network Interface information.
*/
......@@ -47,6 +54,7 @@ class NetworkInterfaceTest extends AwsCloudTestCase {
// Add a new Network Interface.
$add = $this->createNetworkInterfaceTestData();
for ($i = 0; $i < AWS_CLOUD_NETWORK_INTERFACE_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$num = $i + 1;
......@@ -68,14 +76,6 @@ class NetworkInterfaceTest extends AwsCloudTestCase {
'@name' => $add[$i]['name'],
]));
// Make sure View.
/*
$this->drupalGet("/clouds/aws_cloud/$cloud_context/network_interface/$num");
$this->assertResponse(200, t('Add | View | HTTP 200: Network Interface #@num', array('@num' => $num)));
$this->assertNoText(t('Notice'), t('Add | View | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Add | View | Make sure w/o Warnings'));
*/
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/network_interface");
$this->assertResponse(200, t('Add | List | HTTP 200: Network Interface #@num', ['@num' => $num]));
......@@ -84,7 +84,7 @@ class NetworkInterfaceTest extends AwsCloudTestCase {
for ($j = 0; $j < $i + 1; $j++) {
$this->assertText($add[$j]['name'],
t('Make sure w/ Listing: @name',
['@name' => $add[$j]['name']]));
['@name' => $add[$j]['name']]));
}
}
......@@ -135,68 +135,42 @@ class NetworkInterfaceTest extends AwsCloudTestCase {
]));
}
}
//
// // Delete Network Interface.
// for ($i = 0; $i < AWS_CLOUD_NETWORK_INTERFACE_REPEAT_COUNT; $i++) {
// $num = $i + 1;
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/network_interface/$num/delete");
// $this->assertResponse(200, t('HTTP 200: Delete | Network Interface #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->drupalPostForm("/clouds/aws_cloud/$cloud_context/network_interface/$num/delete",
// [],
// t('Delete'));
//
// $this->assertResponse(200, t('Delete | HTTP 200: The Cloud Network Interface #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->assertText($edit[$i]['name'], t('Name: @name ', ['@name' => $edit[$i]['name']]));
// $this->assertText(t('The AWS Cloud Network Interface "@name" has been deleted.', [
// '@name' => $edit[$i]['name'],
// ]),
// t('Confirm Message') . ': '
// . t('Delete | The AWS Cloud Network Interface "@name" has been deleted.', [
// '@name' => $edit[$i]['name'],
// ]));
//
// // Make sure listing.
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/network_interface");
// $this->assertResponse(200, t('Delete | HTTP 200: Network Interface #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
// /*
// for ($j = 0; $j < $i + 1; $j++) { // 3 times
// $this->assertNoText($edit[$i]['name'],
// t('Delete | List | Make sure w/ Listing: @name', array(
// '@name' => $edit[$i]['name'])));
// }
// */
// }
// Filtering scripting information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/clouds/aws_cloud/$cloud_context/network_interface', $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$scripting_id = AWS_CLOUD_NETWORK_INTERFACE_REPEAT_COUNT - 1 ;
$this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
*/
// end
// } // End of foreach.
// Delete Network Interface.
for ($i = 0; $i < AWS_CLOUD_NETWORK_INTERFACE_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->drupalGet("/clouds/aws_cloud/$cloud_context/network_interface/$num/delete");
$this->assertResponse(200, t('HTTP 200: Delete | Network Interface #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->drupalPostForm("/clouds/aws_cloud/$cloud_context/network_interface/$num/delete",
[],
t('Delete'));
$this->assertResponse(200, t('Delete | HTTP 200: The Cloud Network Interface #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('Name: @name ', ['@name' => $edit[$i]['name']]));
$this->assertText(t('The AWS Cloud Network Interface "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Network Interface "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/network_interface");
$this->assertResponse(200, t('Delete | HTTP 200: Network Interface #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
}
}
/**
*
*/
private function createNetworkInterfaceTestData() {
$this->random = new Random();
$data = [];
for ($i = 0; $i < AWS_CLOUD_NETWORK_INTERFACE_REPEAT_COUNT; $i++) {
......
......@@ -4,6 +4,8 @@ namespace Drupal\Tests\aws_cloud\Functional\Ec2;
use Drupal\Component\Utility\Random;
use Drupal\Tests\aws_cloud\Functional\Utils;
// Updated by yas 2016/06/23
// Updated by yas 2016/06/02
// Updated by yas 2016/05/31
......@@ -30,6 +32,14 @@ class SecurityGroupTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
return [
'vpc_id' => 'vpc-' . $this->random->name(8, TRUE),
'cidr_block' => Utils::getRandomCidr(),
'group_id' => 'sg-' . $this->random->name(8, TRUE),
];
}
/**
* Tests CRUD for Security Group information.
*/
......@@ -47,6 +57,7 @@ class SecurityGroupTest extends AwsCloudTestCase {
// Add a new Security Group.
$add = $this->createSecurityGroupTestData();
for ($i = 0; $i < AWS_CLOUD_SECURITY_GROUP_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$num = $i + 1;
......@@ -59,20 +70,12 @@ class SecurityGroupTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Add | Make sure w/o Warnings'));
$this->assertText($add[$i]['group_name'], t('Add | Key Pair: @group_name ', ['@group_name' => $add[$i]['group_name']]));
$this->assertText(t('The AWS Cloud Security Group "@group_name" has been created.', [
'@group_name' => $add[$i]['group_name'],
]),
t('Confirm Message') . ': '
. t('Add | The AWS Cloud Security Group "@group_name" has been created.', [
'@group_name' => $add[$i]['group_name'],
]));
// Make sure View.
/*
$this->drupalGet("/clouds/aws_cloud/$cloud_context/security_group/$num");
$this->assertResponse(200, t('Add | View | HTTP 200: Security Group #@num', array('@num' => $num)));
$this->assertNoText(t('Notice'), t('Add | View | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Add | View | Make sure w/o Warnings'));
*/
'@group_name' => $add[$i]['group_name'],
]),
t('Confirm Message') . ': '
. t('Add | The AWS Cloud Security Group "@group_name" has been created.', [
'@group_name' => $add[$i]['group_name'],
]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/security_group");
......@@ -105,12 +108,12 @@ class SecurityGroupTest extends AwsCloudTestCase {
$this->assertNoText(t('Notice'), t('Edit | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Edit | Make sure w/o Warnings'));
$this->assertText(t('The AWS Cloud Security Group "@name" has been saved.', array(
'@name' => $edit[$i]['name'],
)),
t('Confirm Message') . ': '
. t('Edit | The AWS Cloud Security Group "@name" has been saved.', array(
'@name' => $edit[$i]['name'],
)));
'@name' => $edit[$i]['name'],
)),
t('Confirm Message') . ': '
. t('Edit | The AWS Cloud Security Group "@name" has been saved.', array(
'@name' => $edit[$i]['name'],
)));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/security_group");
......@@ -119,70 +122,44 @@ class SecurityGroupTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Edit | List | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('key_pair: @name ',
array('@name' => $edit[$i]['name'])));
array('@name' => $edit[$i]['name'])));
}
// // Delete Security Group.
// for ($i = 0; $i < AWS_CLOUD_SECURITY_GROUP_REPEAT_COUNT; $i++) {
// $num = $i + 1;
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/security_group/$num/delete");
// $this->assertResponse(200, t('Delete | HTTP 200: Security Group #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->drupalPostForm("/clouds/aws_cloud/$cloud_context/security_group/$num/delete",
// [],
// t('Delete'));
//
// $this->assertResponse(200, t('Delete | HTTP 200: The Cloud Security Group #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->assertText($add[$i]['group_name'], t('Group Name: @group_name ', ['@group_name' => $add[$i]['group_name']]));
// $this->assertText(t('The AWS Cloud Security Group "@group_name" has been deleted.', [
// '@group_name' => $add[$i]['group_name'],
// ]),
// t('Confirm Message') . ': '
// . t('Delete | The AWS Cloud Security Group "@group_name" has been deleted.', [
// '@group_name' => $add[$i]['group_name'],
// ]));
//
// // Make sure listing.
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/security_group");
// $this->assertResponse(200, t('HTTP 200: Delete | Security Group #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
// /*
// for ($j = 0; $j < $i + 1; $j++) { // 3 times
// $this->assertNoText($add[$i]['group_name'],
// t('Delete | List | Make sure w/ Listing: @group_name', array(
// '@group_name' => $add[$i]['group_name'])));
// }
// */
// }
// Filtering scripting information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/clouds/aws_cloud/$cloud_context/security_group', $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$scripting_id = AWS_CLOUD_SECURITY_GROUP_REPEAT_COUNT - 1 ;
$this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
*/
// end
// } // End of foreach.
// Delete Security Group.
for ($i = 0; $i < AWS_CLOUD_SECURITY_GROUP_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->drupalGet("/clouds/aws_cloud/$cloud_context/security_group/$num/delete");
$this->assertResponse(200, t('Delete | HTTP 200: Security Group #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->drupalPostForm("/clouds/aws_cloud/$cloud_context/security_group/$num/delete",
[],
t('Delete'));
$this->assertResponse(200, t('Delete | HTTP 200: The Cloud Security Group #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->assertText($add[$i]['group_name'], t('Group Name: @group_name ', ['@group_name' => $add[$i]['group_name']]));
$this->assertText(t('The AWS Cloud Security Group "@group_name" has been deleted.', [
'@group_name' => $add[$i]['group_name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Security Group "@group_name" has been deleted.', [
'@group_name' => $add[$i]['group_name'],
]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/security_group");
$this->assertResponse(200, t('HTTP 200: Delete | Security Group #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
}
}
/**
*
*/
private function createSecurityGroupTestData($isEdit = FALSE) {
$this->random = new Random();
$data = [];
for ($i = 0; $i < AWS_CLOUD_SECURITY_GROUP_REPEAT_COUNT; $i++) {
......
......@@ -4,6 +4,8 @@ namespace Drupal\Tests\aws_cloud\Functional\Ec2;
use Drupal\Component\Utility\Random;
use Drupal\Tests\aws_cloud\Functional\Utils;
// Updated by yas 2016/06/23
// Updated by yas 2016/06/02
// Updated by yas 2016/05/31
......@@ -31,6 +33,15 @@ class SnapshotTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
return [
'snapshot_id' => 'snap-' . $this->random->name(17, TRUE),
'cidr_block' => Utils::getRandomCidr(),
'group_id' => 'sg-' . $this->random->name(8, TRUE),
'start_time' => date('c'),
];
}
/**
* Tests CRUD for Snapshot information.
*/
......@@ -46,6 +57,7 @@ class SnapshotTest extends AwsCloudTestCase {
// Add a new Snapshot.
$add = $this->createSnapshotTestData();
for ($i = 0; $i < AWS_CLOUD_SNAPSHOT_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$num = $i + 1;
......@@ -57,8 +69,8 @@ class SnapshotTest extends AwsCloudTestCase {
$this->assertNoText(t('Notice'), t('Add | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Add | Make sure w/o Warnings'));
$this->assertText(t('The AWS Cloud Snapshot "@name', [
'@name' => $add[$i]['name'],
]),
'@name' => $add[$i]['name'],
]),
t('Confirm Message') . ': '
. t('The AWS Cloud Snapshot "@name" has been created.', [
'@name' => $add[$i]['name'],
......@@ -68,26 +80,11 @@ class SnapshotTest extends AwsCloudTestCase {
'@name' => $add[$i]['name'],
]));
// Make sure View.
/*
$this->drupalGet("/clouds/aws_cloud/$cloud_context/snapshot/$num");
$this->assertResponse(200, t('Add | View | HTTP 200: Snapshot #@num', array('@num' => $num)));
$this->assertNoText(t('Notice'), t('Add | View | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Add | View | Make sure w/o Warnings'));
*/
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/snapshot");
$this->assertResponse(200, t('HTTP 200: List | Snapshot #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Add | List | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Add | List | Make sure w/o Warnings'));
/*
for ($j = 0; $j < $i + 1; $j++) {
$this->assertText($add[$i]['name'],
t('Add | List | Make sure w/ Listing: @name', array(
'@name' => $add[$i]['name'])));
}
*/
}
// Edit an Snapshot information.
......@@ -128,65 +125,41 @@ class SnapshotTest extends AwsCloudTestCase {
}
}
//
// // Delete Snapshot.
// for ($i = 0; $i < AWS_CLOUD_SNAPSHOT_REPEAT_COUNT; $i++) {
//
// $num = $i + 1;
//
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/snapshot/$num/delete");
// $this->assertResponse(200, t('Delete | HTTP 200: Snapshot #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->drupalPostForm("/clouds/aws_cloud/$cloud_context/snapshot/$num/delete",
// [],
// t('Delete'));
//
// $this->assertResponse(200, t('Delete | HTTP 200: The Cloud Snapshot #@num', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
// $this->assertText($edit[$i]['name'], t('Name: @name ', ['@name' => $edit[$i]['name']]));
// $this->assertText(t('The AWS Cloud Snapshot "@name" has been deleted.', ['@name' => $edit[$i]['name']]),
// t('Confirm Message') . ': ' . t('Delete | The AWS Cloud Snapshot "@name" has been deleted.', ['@name' => $edit[$i]['name']]));
//
// // Make sure listing.
// $this->drupalGet("/clouds/aws_cloud/$cloud_context/snapshot");
// $this->assertResponse(200, t('Delete | HTTP 200: Snapshot', ['@num' => $num]));
// $this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
// $this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
// /*
// for ($j = 0; $j < $i + 1; $j++) { // 3 times
// $this->assertNoText($edit[$i]['name'],
// t('Delete | List | Make sure w/ Listing: @name', array(
// '@name' => $edit[$i]['name'])));
// }
// */
// }
// Filtering scripting information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/clouds/aws_cloud/$cloud_context/snapshot', $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$scripting_id = AWS_CLOUD_SNAPSHOT_REPEAT_COUNT - 1 ;
$this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
*/
// end
// } // End of foreach.
$options = ['query' => ['destination' => "/clouds/aws_cloud/$cloud_context/snapshot"]];
// Delete Snapshot.
for ($i = 0; $i < AWS_CLOUD_SNAPSHOT_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->drupalGet("/clouds/aws_cloud/$cloud_context/snapshot/$num/delete");
$this->assertResponse(200, t('Delete | HTTP 200: Snapshot #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->drupalPostForm("/clouds/aws_cloud/$cloud_context/snapshot/$num/delete",
[],
t('Delete'),
$options);
$this->assertResponse(200, t('Delete | HTTP 200: The Cloud Snapshot #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('Name: @name ', ['@name' => $edit[$i]['name']]));
$this->assertText(t('The AWS Cloud Snapshot "@name" has been deleted.', ['@name' => $edit[$i]['name']]),
t('Confirm Message') . ': ' . t('Delete | The AWS Cloud Snapshot "@name" has been deleted.', ['@name' => $edit[$i]['name']]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/snapshot");
$this->assertResponse(200, t('Delete | HTTP 200: Snapshot', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Delete | List | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | List | Make sure w/o Warnings'));
}
}
/**
*
*/
private function createSnapshotTestData() {
$this->random = new Random();
$data = [];
for ($i = 0; $i < AWS_CLOUD_SNAPSHOT_REPEAT_COUNT; $i++) {
......
......@@ -30,6 +30,13 @@ class VolumeTest extends AwsCloudTestCase {
];
}
protected function getMockDataTemplateVars() {
return [
'volume_id' => 'vol-' . $this->random->name(17, TRUE),
'create_time' => date('c'),
];
}
/**
* Tests CRUD for Volume information.
*/
......@@ -45,6 +52,7 @@ class VolumeTest extends AwsCloudTestCase {
// Add a new Volume.
$add = $this->createVolumeTestData();
for ($i = 0; $i < AWS_CLOUD_VOLUME_REPEAT_COUNT; $i++) {
$this->reloadMockData();
$num = $i + 1;
......@@ -57,21 +65,13 @@ class VolumeTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Add | Make sure w/o Warnings'));
$this->assertText($add[$i]['name'], t('Add | Volume: @name ', ['@name' => $add[$i]['name']]));
$this->assertText(t('The AWS Cloud Volume "@name', [
'@name' => $add[$i]['name'],
]),
'@name' => $add[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Add | The AWS Cloud Volume "@name" has been created.', [
'@name' => $add[$i]['name'],
]));
// Make sure View.
/*
$this->drupalGet("/clouds/aws_cloud/$cloud_context/volume/$num");
$this->assertResponse(200, t('Add | View | HTTP 200: Volume #@num', array('@num' => $num)));
$this->assertNoText(t('Notice'), t('Add | View | ake sure w/o Notice'));
$this->assertNoText(t('warning'), t('Add | View | Make sure w/o Warnings'));
*/
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/volume");
$this->assertResponse(200, t('HTTP 200: Add | List | Volume #@num', ['@num' => $num]));
......@@ -105,8 +105,8 @@ class VolumeTest extends AwsCloudTestCase {
$this->assertNoText(t('Notice'), t('Edit | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Edit | Make sure w/o Warnings'));
$this->assertText(t('The AWS Cloud Volume "@name" has been saved.', [
'@name' => $edit[$i]['name'],
]),
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Edit | The AWS Cloud Volume "@name" has been saved.', [
'@name' => $edit[$i]['name'],
......@@ -144,12 +144,12 @@ class VolumeTest extends AwsCloudTestCase {
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
$this->assertText($edit[$i]['name'], t('Delete | Name: @name ', ['@name' => $edit[$i]['name']]));
$this->assertText(t('The AWS Cloud Volume "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Volume "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]));
'@name' => $edit[$i]['name'],
]),
t('Confirm Message') . ': '
. t('Delete | The AWS Cloud Volume "@name" has been deleted.', [
'@name' => $edit[$i]['name'],
]));
// Make sure listing.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/volume");
......@@ -157,31 +157,12 @@ class VolumeTest extends AwsCloudTestCase {
$this->assertNoText(t('Notice'), t('Delete | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Delete | Make sure w/o Warnings'));
}
// Filtering scripting information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/clouds/aws_cloud/$cloud_context/volume', $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$scripting_id = AWS_CLOUD_VOLUME_REPEAT_COUNT - 1 ;
$this->assertText('x1', t('Confirm Item:') . ' ' . 'x1.large');
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
*/
// end
// } // End of foreach.
}
/**
*
*/
private function createVolumeTestData() {
$this->random = new Random();
$data = [];
for ($i = 0; $i < AWS_CLOUD_VOLUME_REPEAT_COUNT; $i++) {
......
<?php
namespace Drupal\Tests\aws_cloud\Functional;
class Utils {
public static function getRandomPublicIp() {
return implode('.', [rand(0, 254), rand(0, 255), rand(0, 255), rand(1, 255)]);
}
public static function getRandomPrivateIp() {
$private_ips = [
implode('.', ['10', rand(0, 255), rand(0, 255), rand(1, 255)]),
implode('.', ['172', rand(16, 31), rand(0, 255), rand(1, 255)]),
implode('.', ['192', '168' , rand(0, 255), rand(1, 255)]),
];
return $private_ips[array_rand($private_ips)];
}
public static function getRandomCidr() {
$cidrs = [
implode('.', ['10' , rand(0, 255), rand(0, 255), rand(1, 255)]) . '/8' ,
implode('.', ['172', rand(16, 31) , '0' , '0' ]) . '/16',
implode('.', ['192', '168' , rand(0, 255), '0' ]) . '/24',
];
return $cidrs[array_rand($cidrs)];
}
public static function getPublicDns($region, $ip) {
$ip_parts = explode('.', $ip);
return sprintf('ec2-%d-%d-%d-%d.%s.compute.amazonaws.com',
$ip_parts[0], $ip_parts[1], $ip_parts[2], $ip_parts[3], $region);
}
public static function getPrivateDns($region, $ip) {
$ip_parts = explode('.', $ip);
return sprintf('ip-%d-%d-%d-%d.%s.compute.internal',
$ip_parts[0], $ip_parts[1], $ip_parts[2], $ip_parts[3], $region);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment