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

Issue #3015916 by Xiaohua Guan, yas, baldwinlouie: Can't show all security...

Issue #3015916 by Xiaohua Guan, yas, baldwinlouie: Can't show all security groups in instance detail page
parent 129ef147
No related branches found
No related tags found
No related merge requests found
......@@ -283,6 +283,13 @@ class Instance extends CloudContentEntityBase implements InstanceInterface {
return $this->get('security_groups')->value;
}
/**
* {@inheritdoc}
*/
public function setSecurityGroups($securityGroups) {
return $this->set('security_groups', $securityGroups);
}
/**
* {@inheritdoc}
*/
......
......@@ -656,6 +656,7 @@ class AwsEc2Service implements AwsEc2ServiceInterface {
$entity->setPrivateDns($instance['PrivateDnsName']);
}
$entity->setSecurityGroups(implode(', ', $security_groups));
$entity->setRefreshed($timestamp);
$entity->set_launch_time($instance['LaunchTime']->__toString());
$entity->setTerminationTimestamp($termination_timestamp);
......
......@@ -6,3 +6,16 @@ DescribeInstances:
TerminateInstances:
TerminatingInstances:
- InstanceId: {{instance_id}}
DescribeSecurityGroups:
SecurityGroups: []
DescribeKeyPairs:
KeyPairs: []
DescribeAddresses:
Addresses: []
DescribeNetworkInterfaces:
NetworkInterfaces: []
DescribeSnapshots:
Snapshots: []
DescribeVolumes:
Volumes: []
......@@ -36,6 +36,7 @@ class InstanceTest extends AwsCloudTestCase {
'list aws cloud instance',
'edit own aws cloud instance',
'delete own aws cloud instance',
'view own aws cloud instance',
'list cloud server template',
'launch server template',
......@@ -78,7 +79,6 @@ class InstanceTest extends AwsCloudTestCase {
*/
public function testInstance() {
$cloud_context = $this->cloud_context;
$this->createServerTemplate();
// List Instance for Amazon EC2.
......@@ -210,6 +210,41 @@ class InstanceTest extends AwsCloudTestCase {
}
}
/**
* Tests updating instances.
*/
function testUpdateInstances() {
$cloud_context = $this->cloud_context;
$this->createServerTemplate();
// Launch a new Instance.
$add = $this->createInstanceTestData();
$this->addInstanceMockData($add[0]['name'], $add[0]['key_pair_name']);
$this->drupalPostForm("/clouds/design/server_template/$cloud_context/1/launch",
[],
t('Launch'));
$this->assertResponse(200, t('HTTP 200: Launch | A New Cloud Instance 1'));
$this->assertNoText(t('Notice'), t('Launch | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('Launch | Make sure w/o Warnings'));
// Change security groups.
$security_group_name1 = $this->random->name(8, TRUE);
$security_group_name2 = $this->random->name(8, TRUE);
$this->updateSecurityGroupsInMockData($security_group_name1, $security_group_name2);
// Run cron job to update instances.
$key = \Drupal::state()->get('system.cron_key');
$this->drupalGet('/cron/' . $key);
$this->assertResponse(204);
// Verify security group.
$this->drupalGet("/clouds/aws_cloud/$cloud_context/instance/1");
$this->assertResponse(200, t('View | HTTP 200: The Cloud Instance 1'));
$this->assertNoText(t('Notice'), t('View | Make sure w/o Notice'));
$this->assertNoText(t('warning'), t('View | Make sure w/o Warnings'));
$this->assertText("$security_group_name1, $security_group_name2", t('Security Group'));
}
private function createInstanceTestData() {
$data = [];
......@@ -285,6 +320,13 @@ class InstanceTest extends AwsCloudTestCase {
$this->updateMockDataToConfig($mock_data);
}
private function updateSecurityGroupsInMockData($security_group_name1, $security_group_name2) {
$mock_data = $this->getMockDataFromConfig();
$mock_data['DescribeInstances']['Reservations'][0]['Instances'][0]['SecurityGroups']
= [['GroupName' => $security_group_name1], ['GroupName' => $security_group_name2]];
$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;
......
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