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

Issue #3009050 by Xiaohua Guan, baldwinlouie, yas: Update SimpleTest test...

Issue #3009050 by Xiaohua Guan, baldwinlouie, yas: Update SimpleTest test cases for module aws_cloud
parent e59f0006
No related branches found
No related tags found
No related merge requests found
Showing
with 386 additions and 657 deletions
...@@ -2,10 +2,12 @@ name: Cloud ...@@ -2,10 +2,12 @@ name: Cloud
type: module type: module
description: Allows users to manage Clouds. description: Allows users to manage Clouds.
package: Cloud package: Cloud
dependencies:
- drupal:views
version : 8.x-1.x version : 8.x-1.x
core : 8.x core : 8.x
project : cloud project : cloud
scripts: scripts:
- js/cloud.js - js/cloud.js
\ No newline at end of file
...@@ -8,10 +8,10 @@ views.field.cloud_list_instances: ...@@ -8,10 +8,10 @@ views.field.cloud_list_instances:
type: label type: label
label: 'Text to display' label: 'Text to display'
views.field.cloud_server_template_list: views.field.cloud_list_templates:
type: views_field type: views_field
label: 'Link to cloud server template list' label: 'Link to cloud server template list'
mapping: mapping:
text: text:
type: label type: label
label: 'Text to display' label: 'Text to display'
\ No newline at end of file
...@@ -2,6 +2,9 @@ name: 'AWS Cloud' ...@@ -2,6 +2,9 @@ name: 'AWS Cloud'
description: 'Amazon Web Services Compatible Cloud (incl. Amazon EC2, OpenStack nova, Eucalyptus and Cloud n) Implementation' description: 'Amazon Web Services Compatible Cloud (incl. Amazon EC2, OpenStack nova, Eucalyptus and Cloud n) Implementation'
package: Cloud Service Provider package: Cloud Service Provider
dependencies: dependencies:
- drupal:views
- drupal:options
- drupal:user
- cloud - cloud
- cloud_server_template - cloud_server_template
- cloud_pricing - cloud_pricing
......
aws_cloud.settings:
type: config_object
mapping:
aws_cloud_test_mode:
type: boolean
aws_cloud_instance_types:
type: string
aws_cloud_notification_frequency:
type: integer
aws_cloud_notification:
type: integer
aws_cloud_notification_criteria:
type: integer
aws_cloud_notification_subject:
type: string
aws_cloud_notification_msg:
type: string
aws_cloud_mock_data:
type: string
views.access.ViewsCloudContextAccess:
type: mapping
mapping:
perm:
type: string
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
namespace Drupal\aws_cloud\Service; namespace Drupal\aws_cloud\Service;
use Aws\MockHandler;
use Aws\Result;
use Aws\Api\DateTimeResult;
use Aws\Ec2\Ec2Client; use Aws\Ec2\Ec2Client;
use Aws\Ec2\Exception\Ec2Exception; use Aws\Ec2\Exception\Ec2Exception;
use Drupal\aws_cloud\Entity\Ec2\ElasticIp; use Drupal\aws_cloud\Entity\Ec2\ElasticIp;
...@@ -118,8 +122,10 @@ class AwsEc2Service implements AwsEc2ServiceInterface { ...@@ -118,8 +122,10 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
$this->logger = $logger_factory->get('aws_ec2_service'); $this->logger = $logger_factory->get('aws_ec2_service');
// setup the configuration factory // setup the configuration factory
$this->configFactory = $config_factory; $this->configFactory = $config_factory;
// setup the dryRun flag // setup the dryRun flag
$this->dryRun = (bool) $this->configFactory->get('aws_cloud.settings')->get('aws_cloud_test_mode'); $this->dryRun = (bool) $this->configFactory->get('aws_cloud.settings')->get('aws_cloud_test_mode');
// setup the messenger // setup the messenger
$this->messenger = $messenger; $this->messenger = $messenger;
// setup the $this->t() // setup the $this->t()
...@@ -146,6 +152,7 @@ class AwsEc2Service implements AwsEc2ServiceInterface { ...@@ -146,6 +152,7 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
$credentials = $this->cloudConfigPluginManager->loadCredentials(); $credentials = $this->cloudConfigPluginManager->loadCredentials();
try { try {
$ec2_client = Ec2Client::factory($credentials); $ec2_client = Ec2Client::factory($credentials);
$this->addMockHandler($ec2_client);
} }
catch (\Exception $e) { catch (\Exception $e) {
$ec2_client = NULL; $ec2_client = NULL;
...@@ -155,6 +162,38 @@ class AwsEc2Service implements AwsEc2ServiceInterface { ...@@ -155,6 +162,38 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
return $ec2_client; return $ec2_client;
} }
private function addMockHandler($ec2_client) {
$mock_data = $this->configFactory->get('aws_cloud.settings')->get('aws_cloud_mock_data');
if ($this->dryRun && $mock_data) {
$func = function ($command, $request) {
$mock_data = \Drupal::service('config.factory')
->get('aws_cloud.settings')
->get('aws_cloud_mock_data');
$mock_data = json_decode($mock_data, true);
$command_name = $command->getName();
if (isset($mock_data[$command_name])) {
$result_data = $mock_data[$command_name];
if ($command_name == 'DescribeInstances') {
foreach ($result_data['Reservations'] as &$reservation) {
foreach ($reservation['Instances'] as &$instance) {
if (!empty($instance['LaunchTime'])) {
$instance['LaunchTime'] = new DateTimeResult($instance['LaunchTime']);
}
}
}
}
return new Result($result_data);
}
else {
return new Result();
}
};
$ec2_client->getHandlerList()->setHandler(new MockHandler([$func, $func]));
}
}
/** /**
* @param String $operation * @param String $operation
* The operation to perform * The operation to perform
...@@ -523,7 +562,6 @@ class AwsEc2Service implements AwsEc2ServiceInterface { ...@@ -523,7 +562,6 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
// call the api and get all instances // call the api and get all instances
$result = $this->describeInstances(); $result = $this->describeInstances();
if ($result != NULL) { if ($result != NULL) {
$all_instances = $this->loadAllEntities($entity_type); $all_instances = $this->loadAllEntities($entity_type);
...@@ -538,7 +576,6 @@ class AwsEc2Service implements AwsEc2ServiceInterface { ...@@ -538,7 +576,6 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
foreach ($result['Reservations'] as $reservation) { foreach ($result['Reservations'] as $reservation) {
foreach ($reservation['Instances'] as $instance) { foreach ($reservation['Instances'] as $instance) {
// keep track of instances that do not exist anymore // keep track of instances that do not exist anymore
// delete them after saving the rest of the instances // delete them after saving the rest of the instances
if (isset($stale[$instance['InstanceId']])) { if (isset($stale[$instance['InstanceId']])) {
......
<?php
/**
* @file
* Base Class for all the aws_cloud test cases
* The base class does not provide any test classes.
* It contains common methods that are used by the
* actual test classes.
*
*/
module_load_include('inc' , 'aws_cloud', 'aws_cloud.test') ;
class AwsCloudTestCase extends DrupalWebTestCase {
protected $userList = array();
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(array(
'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', array('@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(array(
'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 = array(
'amazon_ec2' => array(
'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', array('@keyname' => $key_name)),
t('Confirmed: Key Pair deleted successfully: @keyname', array('@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', array(
'query' => array(
'destination' => 'clouds/' . $cloud . '/instances',
),
));
}
/**
* Helper function to refresh an images listing page
*/
protected function refreshImages($cloud) {
$this->drupalGet('clouds/' . $cloud . '/getimagedata', array(
'query' => array(
'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 = array();
$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'", array($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'", array('SimpleTest_Volume', $cloud)));
}
/**
* Helper function to create ssh keys
*/
protected function createSSHKey($key_name, $cloud) {
$edit = array(
'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', array(
'query' => array(
'key_name' => $key_name,
),
));
}
/**
* Helper function to refresh the clouds page
*/
protected function refreshPageAll() {
$this->drupalGet('clouds/getdata', array(
'query' => array(
'src' => 'clouds',
),
));
}
}
class AwsCloudListTestCase extends AwsCloudTestCase {
public static function getInfo() {
return array(
'name' => 'AWS Cloud - Listing Pages',
'description' => 'AWS Cloud - Test all aws_cloud listing pages',
'group' => 'Cloud',
);
}
/**
* Test Main Cloud Listing Page
*/
public function testCloudList() {
$this->drupalGet('clouds');
$this->assertResponse(200, t('HTTP 200: Clouds Page'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
}
/**
* Test Main Cloud Listing Page Refresh
*/
public function testCloudRefresh() {
$this->refreshPageAll();
$this->drupalGet('clouds');
$this->assertResponse(200, t('HTTP 200: Clouds Page'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
}
/**
* Test the Sub Cloud Listing Page
*/
public function testSubCloudLinks() {
$clouds = $this->getClouds();
foreach ($clouds as $cloud) {
$this->testSubCloudList($cloud);
$this->testSubCloudLaunchList($cloud);
$this->testSubCloudInstancesList($cloud);
$this->testSubCloudImagesAllList($cloud);
$this->testSubCloudImagesOwnerList($cloud);
$this->testSecurityGroupsList($cloud);
$this->testSubCloudImagesOwnerList($cloud);
$this->testSecurityGroupsList($cloud);
$this->testSSHKeysList($cloud);
$this->testElasticIpList($cloud);
$this->testVolumesList($cloud);
$this->testSnapshotsList($cloud);
}
}
/**
* Tests refreshing the data and returning to
* Listing pages
*/
public function testRefresh() {
$clouds = $this->getClouds();
foreach ($clouds as $cloud) {
$this->testSubCloudList($cloud, TRUE);
$this->testSubCloudInstancesList($cloud, TRUE);
$this->testSubCloudImagesAllList($cloud, TRUE);
$this->testSSHKeysList($cloud, TRUE);
$this->testElasticIpList($cloud, TRUE);
$this->testVolumesList($cloud, TRUE);
$this->testSnapshotsList($cloud, TRUE);
}
}
/**
* Test SubCloud Listing Page
*/
private function testSubCloudList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshPageAll();
}
$this->drupalGet('clouds/' . $cloud);
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' Listing page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test SubCloud Launch Page
*/
private function testSubCloudLaunchList($cloud) {
//design/server_templates/amazon_ec2/list
$this->drupalGet('design/server_templates/' . $cloud . '/list');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' Instance Templates page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test SubCloud Instances Listing Page
*/
private function testSubCloudInstancesList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshInstances($cloud);
}
$this->drupalGet('clouds/' . $cloud . '/instances');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' Instances page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test SubCloud Images Listing page
*/
private function testSubCloudImagesAllList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshImages($cloud);
}
$this->drupalGet('clouds/' . $cloud . '/images');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' Images All page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test SubCloud Images Listing page by Owner
*/
private function testSubCloudImagesOwnerList($cloud) {
$this->drupalGet('clouds/' . $cloud . '/images/owner');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' Images By Owner page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test security group listing page
*/
private function testSecurityGroupsList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshSecurityGroups($cloud);
}
$this->drupalGet('clouds/' . $cloud . '/security_groups');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' Security Groups page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test SSH Keys Listing page
*/
private function testSSHKeysList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshSSHKeys($cloud);
}
$this->drupalGet('clouds/' . $cloud . '/ssh_keys');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' SSH Keys page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test ElasticIP Listing Page
*/
private function testElasticIpList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshElasticIP($cloud);
}
$this->drupalGet('clouds/' . $cloud . '/elastic_ips');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' Elastic IPs page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test Volumes Listing Page
*/
private function testVolumesList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshVolumes($cloud);
}
$this->drupalGet('clouds/' . $cloud . '/ebs_volumes');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' EBS Volumes page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
/**
* Test Snapshots Listing Page
*/
private function testSnapshotsList($cloud, $refresh = FALSE) {
if ($refresh) {
$this->refreshSnapshots($cloud);
}
$this->drupalGet('clouds/' . $cloud . '/ebs_snapshots');
$this->assertResponse(200, t('HTTP 200:' . $cloud . ' EBS Snapshot page'));
$this->assertNoText(t('Notice'), t('Make sure there are no Notices'));
$this->assertNoText(t('warning'), t('Make sure there are no Warnings'));
}
}
class AwsCloudSSHTestCase extends AwsCloudTestCase {
public static function getInfo() {
return array(
'name' => 'AWS Cloud - SSH Key',
'description' => 'AWS Cloud - Test SSH Key Creation',
'group' => 'Cloud',
);
}
/**
* Test ssh key creation
*/
public function testCreateSSHKey() {
$clouds = $this->getClouds();
foreach ($clouds as $cloud) {
$this->refreshInstances($cloud);
$key_name = $this->privileged_user->name . '_simple_test';
$this->createSSHKey($key_name, $cloud);
$this->assertText (t('Created a Key Pair Successfully.' ),
t('Confirmed: Created a Key Pair Successfully for SubCloud: ' . $cloud));
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings' ));
//Delete the key after creation
$this->deleteSSHKey($key_name, $cloud);
$this->assertText (t('Key Pair deleted successfully: @keyname', array('@keyname' => $key_name)),
t('Confirmed: Key Pair deleted successfully: @keyname', array('@keyname' => $key_name)));
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
}
}
}
class AwsCloudSecurityTestCase extends AwsCloudTestCase {
public static function getInfo() {
return array(
'name' => 'AWS Cloud - Security Group',
'description' => 'AWS Cloud - Test security group creation',
'group' => 'Cloud',
);
}
/**
* Test Security Group Creation
*/
public function testSecurityGroupCreation() {
$clouds = $this->getClouds();
foreach ($clouds as $cloud) {
$edit = array(
'cloud_context' => $cloud,
'GroupName_text' => 'SimpleTest_Group',
'GroupDesc_text' => 'SimpleTest_Group Description',
);
$this->drupalPost('clouds/' . $cloud . '/security_groups/create', $edit, t('Create'));
$this->assertText(t('Created a Security Group Successfully'), t('Confirmed: Security Group Created Successfuly for @cloud', array('@cloud' => $cloud)));
$this->assertText(t('SimpleTest_Group'), t('SimpleTest_Group listed after creation'));
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
}
}
/**
* Test Deleting Security Group
*/
public function testDeleteSecurityGroupCreation() {
$clouds = $this->getClouds();
foreach ($clouds as $cloud) {
$this->drupalGet('clouds/' . $cloud . '/security_groups/delete', array(
'query' => array(
'sg_name' => 'SimpleTest_Group',
)
));
$this->assertText(t('Security Group deleted successfully: @group', array('@group' => 'SimpleTest_Group')), t('SimpleTest_Group delete'));
$this->assertNoText(t('Notice' ), t('Make sure w/o Notice' ));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
}
}
}
\ No newline at end of file
<?php
/**
* @file
* Configuration for aws_cloud.test
*
*/
/**
* Updated by yas 2011/06/07
* Updated by yas 2010/12/26
* Created by yas 2010/12/02
*/
define('AMAZON_EC2_API_VERSION' , '2012-06-01' );
// us-east-1
define('AMAZON_EC2_HOST_URI' , 'ec2.amazonaws.com' );
// PLEASE CHANGE THE FOLLOWING CREDENTIALS
define('AMAZON_EC2_AWS_ACCESS_KEY' , '12ABCDEFGHIJKVWXYZ89' );
define('AMAZON_EC2_API_SECRET_KEY' , '123ABC/defGHIjkl34+LMNopq567RSTuvwxYz89Z');
define('AMAZON_EC2_USER_ID' , '123456789012' );
define('AMAZON_S3_IMAGE_UPLOAD_URL' , 'https://s3.amazonaws.com' );
define('AMAZON_EC2_IMAGE_REGISTER_URL', 'https://ec2.amazonaws.com' );
define('AMAZON_EC2_X509_CERTIFICATE' , "-----BEGIN CERTIFICATE-----\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXX==\n-----END CERTIFICATE-----\n" );
DescribeAvailabilityZones:
AvailabilityZones:
- ZoneName: us-west-1
- ZoneName: us-west-2
- ZoneName: us-west-3
AllocateAddress:
PublicIp: 10.0.0.0
CreateImage:
ImageId: dummy image
DescribeInstances:
Reservations:
- Instances: []
OwnerId: 123456789012
ReservationId: r-1234567890abcdef0
#@FIXME move to Reservations area.
InstanceId: '$name'
InstanceType: t2.micro
Placement:
AvailabilityZone: us-west-1c
Tenancy: default
GroupName: ''
HostId: host1
Affinity: affinity1
LaunchTime: '2018-01-01T00:00:00.000Z'
Tags:
- Key: Name
Value: '$name'
SecurityGroups:
- GroupId: sg-e4076980
GroupName: SecurityGroup1
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'
Monitoring:
State: enabled
VpcId: vpc-e867158c
SubnetId: subnet-0b1b1a7d
SourceDestCheck: false
EbsOptimized: false
RootDeviceType: ebs
RootDeviceName: /dev/xvda
ImageId: ami-f46f5993
VirtualizationType: hvm
AmiLaunchIndex: 0
StateTransitionReason: ''
CreateKeyPair:
KeyName: dummy key
KeyFingerprint: dummy fingerprint
CreateNetworkInterface:
NetworkInterfaceId: dummy network interface
Status: pending
VpcId: dummy vpc id
DescribeVpcs:
Vpcs:
VpcId: vpc-1a2b3c4d
CidrBlock: 192.168.0.0/16
CreateSecurityGroup:
GroupId: dummy group
CreateSnapshot:
SnapshotId: dummy snapshot
Status: pending
StartTime: '2018-01-01T00:00:00.000Z'
Encrypted: TRUE
CreateVolume:
VolumeId: dummy volume
CreateTime: '2018-01-01T00:00:00.000Z'
State: creating
<?php <?php
namespace Drupal\aws_cloud\Tests\Config; namespace Drupal\Tests\aws_cloud\Functional\Config;
use Drupal\simpletest\WebTestBase; use Drupal\Tests\BrowserTestBase;
use Drupal\Component\Utility\Random; use Drupal\Component\Utility\Random;
use Drupal\user\Entity\Role;
// Updated by yas 2016/06/02 // Updated by yas 2016/06/02
// Updated by yas 2016/06/01 // Updated by yas 2016/06/01
...@@ -18,14 +19,14 @@ use Drupal\Component\Utility\Random; ...@@ -18,14 +19,14 @@ use Drupal\Component\Utility\Random;
// updated by yas 2015/06/09 // updated by yas 2015/06/09
// created by yas 2015/06/08. // created by yas 2015/06/08.
// module_load_include('test', 'aws_cloud');. // module_load_include('test', 'aws_cloud');.
define('AWS_CLOUD_CONFIG_REPEAT_COUNT', 3); define('AWS_CLOUD_CONFIG_REPEAT_COUNT', 2);
/** /**
* Tests AWS Cloud Config. * Tests AWS Cloud Config.
* *
* @group AWS Cloud * @group AWS Cloud
*/ */
class ConfigTest extends WebTestBase { class ConfigTest extends BrowserTestBase {
/* @FIXME extends ConfigTestCase { */ /* @FIXME extends ConfigTestCase { */
/** /**
...@@ -60,11 +61,16 @@ class ConfigTest extends WebTestBase { ...@@ -60,11 +61,16 @@ class ConfigTest extends WebTestBase {
$config->set('aws_cloud_test_mode', true); $config->set('aws_cloud_test_mode', true);
$web_user = $this->drupalCreateUser([ $web_user = $this->drupalCreateUser([
'list aws cloud provider', 'administer cloud config entities',
'add aws cloud provider', 'add cloud config entities',
'view aws cloud provider', 'edit cloud config entities',
'edit aws cloud provider', 'edit own cloud config entities',
'delete aws cloud provider', 'delete cloud config entities',
'delete own cloud config entities',
'view unpublished cloud config entities',
'view own unpublished cloud config entities',
'view published cloud config entities',
'view own published cloud config entities',
]); ]);
$this->drupalLogin($web_user); $this->drupalLogin($web_user);
} }
...@@ -74,11 +80,8 @@ class ConfigTest extends WebTestBase { ...@@ -74,11 +80,8 @@ class ConfigTest extends WebTestBase {
*/ */
public function testConfig() { public function testConfig() {
// Access to AWS Cloud Menu
// $clouds = $this->getClouds();
// foreach ($clouds as $cloud) {.
// List AWS Cloud for Amazon EC2. // List AWS Cloud for Amazon EC2.
$this->drupalGet('/admin/config/services/cloud/aws_cloud/cloud_context'); $this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | AWS Cloud')); $this->assertResponse(200, t('HTTP 200: List | AWS Cloud'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice')); $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); $this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
...@@ -89,48 +92,39 @@ class ConfigTest extends WebTestBase { ...@@ -89,48 +92,39 @@ class ConfigTest extends WebTestBase {
$num = $i + 1; $num = $i + 1;
$cloud_context[$i] = $add[$i]['cloud_context']; $cloud_context[$i] = $add[$i]['cloud_context'];
$label[$i] = $add[$i]['label']; $label[$i] = $add[$i]['name[0][value]'];
$this->drupalGet('/admin/config/services/cloud/aws_cloud/cloud_context/add'); $this->drupalGet('/admin/structure/cloud_config/add');
$this->assertResponse(200, t('HTTP 200: Add | AWS Cloud Config Form #@num', ['@num' => $num])); $this->assertResponse(200, t('HTTP 200: Add | AWS Cloud Config Form #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice')); $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); $this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->drupalPostForm('/admin/config/services/cloud/aws_cloud/cloud_context/add', $this->drupalPostForm('/admin/structure/cloud_config/add',
$add[$i], $add[$i],
t('Save')); t('Save'));
$this->assertResponse(200, t('HTTP 200: Saved | Aws Cloud Config Form #@num', ['@num' => $num])); $this->assertResponse(200, t('HTTP 200: Saved | Aws Cloud Config Form #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice')); $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); $this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
/* $this->assertText(t('Created the @label Cloud config.', array('@label' => $label[$i])),
$this->assertText(t('AWS cloud information "%label" has been saved.', array('%label' => $label)), t('Add - Saved Message:') . ' '
t('Add - Saved Message:') . ' ' . t('Created the @label Cloud config.', array('@label' => $label[$i])));
. t('AWS cloud information "%label" has been saved.', array('%label' => $label)));
*/
$this->assertText($label[$i], $this->assertText($label[$i],
t('Cloud Display Name: %label', [ t('Name: @label', [
'%label' => $label[$i], '@label' => $label[$i],
]));
$this->assertText($cloud_context[$i],
t('cloud_context: @cloud_context', [
'@cloud_context' => $cloud_context[$i],
])); ]));
// Make sure listing. // Make sure listing.
$this->drupalGet('/admin/config/services/cloud/aws_cloud/cloud_context'); $this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | AWS Cloud #@num', ['@num' => $num])); $this->assertResponse(200, t('HTTP 200: List | AWS Cloud #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice')); $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); $this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
for ($j = 0; $j < $i + 1; $j++) { for ($j = 0; $j < $i + 1; $j++) {
$this->assertText($label[$j], $this->assertText($label[$j],
t('Cloud Display Name @num: %label', [ t('Cloud config @num: @label', [
'@num' => $j + 1, '@num' => $j + 1,
'%label' => $label[$j], '@label' => $label[$j],
]));
$this->assertText($cloud_context[$j],
t('Make sure w/ Listing @num: @cloud_context', [
'@num' => $j + 1,
'@cloud_context' => $cloud_context[$j],
])); ]));
} }
} }
...@@ -142,12 +136,12 @@ class ConfigTest extends WebTestBase { ...@@ -142,12 +136,12 @@ class ConfigTest extends WebTestBase {
$num = $i + 1; $num = $i + 1;
$cloud_context[$i] = $edit[$i]['cloud_context']; $cloud_context[$i] = $edit[$i]['cloud_context'];
$label[$i] = $edit[$i]['label']; $label[$i] = $edit[$i]['name[0][value]'];
unset($edit[$i]['cloud_context']); unset($edit[$i]['cloud_context']);
unset($edit[$i]['cloud_type']); unset($edit[$i]['field_cloud_type']);
$this->drupalPostForm('/admin/config/services/cloud/aws_cloud/cloud_context/' . $cloud_context[$i] . '/edit', $this->drupalPostForm('/admin/structure/cloud_config/' . $num . '/edit',
$edit[$i], $edit[$i],
t('Save')); t('Save'));
$this->assertResponse(200, t('HTTP 200: Edit | AWS Cloud Form #@num', ['@num' => $num])); $this->assertResponse(200, t('HTTP 200: Edit | AWS Cloud Form #@num', ['@num' => $num]));
...@@ -159,96 +153,56 @@ class ConfigTest extends WebTestBase { ...@@ -159,96 +153,56 @@ class ConfigTest extends WebTestBase {
. t('AWS cloud information "%label" has been saved.', array('%label' => $label))); . t('AWS cloud information "%label" has been saved.', array('%label' => $label)));
*/ */
$this->assertText($label[$i], $this->assertText($label[$i],
t('Cloud Display Name: %label', [ t('Cloud config Name: @label', [
'%label' => $label[$i], '@label' => $label[$i],
]));
$this->assertText($cloud_context[$i],
t('cloud_context: @cloud_context', [
'@cloud_context' => $cloud_context[$i],
])); ]));
// Make sure listing. // Make sure listing.
$this->drupalGet('/admin/config/services/cloud/aws_cloud/cloud_context'); $this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | AWS Cloud #@num', ['@num' => $num])); $this->assertResponse(200, t('HTTP 200: List | AWS Cloud #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice')); $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Make sure w/o Warnings')); $this->assertNoText(t('warning'), t('Make sure w/o Warnings'));
for ($j = 0; $j < $i + 1; $j++) { for ($j = 0; $j < $i + 1; $j++) {
$this->assertText($label[$j], $this->assertText($label[$j],
t('Cloud Display Name @num: %label', [ t('Cloud config @num: @label', [
'@num' => $j + 1,
'%label' => $label[$j],
]));
$this->assertText($cloud_context[$j],
t('Make sure w/ Listing @num: @cloud_context', [
'@num' => $j + 1, '@num' => $j + 1,
'@cloud_context' => $cloud_context[$j], '@label' => $label[$j],
])); ]));
} }
} }
// Delete Config Items. // Delete Config Items.
$delete = $this->createConfigTestData(); $delete = $edit;
for ($i = 0; $i < AWS_CLOUD_CONFIG_REPEAT_COUNT; $i++) { for ($i = 0; $i < AWS_CLOUD_CONFIG_REPEAT_COUNT; $i++) {
$num = $i + 1; $num = $i + 1;
$cloud_context[$i] = $delete[$i]['cloud_context']; $label[$i] = $delete[$i]['name[0][value]'];
$label[$i] = $delete[$i]['label'];
$this->drupalGet('/admin/config/services/cloud/aws_cloud/cloud_context/' . $cloud_context[$i] . '/delete'); $this->drupalGet('/admin/structure/cloud_config/' . $num . '/delete');
$this->drupalPostForm('/admin/config/services/cloud/aws_cloud/cloud_context/' . $cloud_context[$i] . '/delete', $this->drupalPostForm('/admin/structure/cloud_config/' . $num . '/delete',
[], [],
t('Delete')); t('Delete'));
$this->assertResponse(200, t('HTTP 200: Delete | AWS Cloud')); $this->assertResponse(200, t('HTTP 200: Delete | AWS Cloud'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice')); $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); $this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
/* $this->assertText(t('The cloud config @label has been deleted.', array('@label' => $label[$i])),
$this->assertText(t('content aws_cloud: deleted %label.', array('%label' => $label)),
t('Deleted Message:') . ' ' t('Deleted Message:') . ' '
. t('content aws_cloud: deleted %label.', array('%label' => $label))); . t('The cloud config @label has been deleted.', array('@label' => $label[$i])));
*/
$this->assertNoText($label[$i],
t('Cloud Display Name: %label', [
'%label' => $label[$i],
]));
$this->assertNoText($cloud_context[$i],
t('cloud_context: @cloud_context', [
'@cloud_context' => $cloud_context[$i],
]));
// Because $cloud_context has been deleted. // Because $cloud_context has been deleted.
// Make sure listing. // Make sure listing.
$this->drupalGet('/admin/config/services/cloud/aws_cloud/cloud_context'); $this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | AWS Cloud #@num', ['@num' => $num])); $this->assertResponse(200, t('HTTP 200: List | AWS Cloud #@num', ['@num' => $num]));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice')); $this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings')); $this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
for ($j = 0; $j < $i + 1; $j++) { for ($j = 0; $j < $i + 1; $j++) {
$this->assertNoText($label[$j], $this->assertNoText($label[$j],
t('Cloud Display Name @num: %label', [ t('Cloud config Name @num: @label', [
'@num' => $j + 1,
'%label' => $label[$j],
]));
$this->assertNoText($cloud_context[$j],
t('Make sure w/ Listing @num: @cloud_context', [
'@num' => $j + 1, '@num' => $j + 1,
'@cloud_context' => $cloud_context[$j], '@label' => $label[$j],
])); ]));
} }
} }
// Filtering pricing information item
/*
$filter = array(
'filter' => 't1',
'operation' => 0,
);
$this->drupalPost("/admin/config/services/cloud/aws_cloud/cloud_context/$cloud_context", $filter, t('Apply'));
$this->assertResponse(200, t('HTTP 200: Search Listings | Filter'));
$xxxxx = AWS_CLOUD_CONFIG_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.
} }
/** /**
...@@ -265,19 +219,18 @@ class ConfigTest extends WebTestBase { ...@@ -265,19 +219,18 @@ class ConfigTest extends WebTestBase {
$num = $i + 1; $num = $i + 1;
$data[] = [ $data[] = [
'cloud_context' => "amazon_us_west_$num", 'cloud_context' => "amazon_us_west_$num",
'cloud_type' => 'amazon_ec2', 'field_cloud_type' => 'amazon_ec2',
'label' => "Amazon EC2 US West ($num) - " . $this->random->name(8, TRUE), 'name[0][value]' => "Amazon EC2 US West ($num) - " . $this->random->name(8, TRUE),
'description' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') . $this->random->string(64, TRUE), 'field_description[0][value]' => "#$num: " . date('Y/m/d H:i:s - D M j G:i:s T Y') . $this->random->string(64, TRUE),
'api_version' => date('Y-m-d'), 'field_api_version[0][value]' => date('Y-m-d'),
'region' => "us-west-$num", 'field_region' => "us-west-$num",
'endpoint' => "ec2.us-west-$num.amazonaws.com", 'field_api_endpoint_uri' => "https://ec2.us-west-$num.amazonaws.com",
'aws_access_key' => $this->random->name(20, TRUE), 'field_secret_key[0][value]' => $this->random->name(20, TRUE),
'aws_secret_key' => $this->random->name(40, TRUE), 'field_access_key[0][value]' => $this->random->name(40, TRUE),
'user_id' => $this->random->name(16, TRUE), 'field_user_id[0][value]' => $this->random->name(16, TRUE),
'image_upload_url' => "https://s3.amazonaws.com/$num", 'field_image_upload_url' => "https://ec2.us-west-$num.amazonaws.com",
'image_register_url' => "ec2.us-west-$num.amazonaws.com", 'field_x_509_certificate[0][value]' => $this->random->string(255, TRUE),
'certificate' => $this->random->string(255, TRUE),
]; ];
} }
......
<?php <?php
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
namespace Drupal\aws_cloud\Tests\Config; namespace Drupal\Tests\aws_cloud\Functional\Config;
/** /**
* *
*/ */
......
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