diff --git a/modules/cloud_service_providers/aws_cloud/aws_cloud.module b/modules/cloud_service_providers/aws_cloud/aws_cloud.module index 7001be19b56fe2df03d833ca311d2594a3e8d186..5c0d720fb498995f3fa6311c23202c55284ef2b5 100644 --- a/modules/cloud_service_providers/aws_cloud/aws_cloud.module +++ b/modules/cloud_service_providers/aws_cloud/aws_cloud.module @@ -10,6 +10,7 @@ use Aws\Exception\AwsException; use Aws\Exception\CredentialsException; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\Instance; use Drupal\aws_cloud\Entity\Ec2\Snapshot; use Drupal\aws_cloud\Entity\Ec2\Volume; @@ -2083,6 +2084,9 @@ function aws_cloud_get_launch_template_data(CloudServerTemplate $server_template // Add tags from the template. $tags_map = []; foreach ($server_template->field_tags ?: [] as $tag_item) { + if (strpos($tag_item->getItemKey, CloudServerTemplate::TAG_CREATED_BY_UID) !== FALSE) { + continue; + } $tags_map[$tag_item->getItemKey()] = $tag_item->getItemValue(); } @@ -2102,8 +2106,8 @@ function aws_cloud_get_launch_template_data(CloudServerTemplate $server_template } $tags_map[CloudServerTemplate::TAG_SSH_KEY] = $key_pair_id; $tags_map[CloudServerTemplate::TAG_SCHEDULE] = $server_template->field_schedule->value; - $tags_map[CloudServerTemplate::TAG_CREATED_BY_UID] = $server_template->getOwner() - ->id(); + $key_uid = AwsCloudEntity::getTagCreatedByUid($server_template->getCloudContext(), CloudServerTemplate::TAG_CREATED_BY_UID); + $tags_map[$key_uid] = $server_template->getOwner()->id(); $tags_map[CloudServerTemplate::TAG_DESCRIPTION] = $server_template->field_description->value; $tags_map[CloudServerTemplate::TAG_WORKFLOW_STATUS] = $server_template->field_workflow_status->value; diff --git a/modules/cloud_service_providers/aws_cloud/src/Entity/Ec2/AwsCloudEntity.php b/modules/cloud_service_providers/aws_cloud/src/Entity/Ec2/AwsCloudEntity.php new file mode 100644 index 0000000000000000000000000000000000000000..27296b32dbb6e4dc0b720293ccad78f0055dc3ad --- /dev/null +++ b/modules/cloud_service_providers/aws_cloud/src/Entity/Ec2/AwsCloudEntity.php @@ -0,0 +1,32 @@ + $tag, + '{site_uuid}' => \Drupal::config('system.site')->get('uuid'), + '{cloud_context}' => $cloud_context, + ]; + return strtr(self::TAG_FORMAT, $context); + } + +} diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/AwsCloudContentForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/AwsCloudContentForm.php index 01fcee73305c1886a5e8a617424f830332dfaf94..926a8c34ec1f08269ce9e46de78a4eed21b46c4c 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/AwsCloudContentForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/AwsCloudContentForm.php @@ -2,7 +2,7 @@ namespace Drupal\aws_cloud\Form\Ec2; -use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; use Drupal\aws_cloud\Traits\AwsCloudEntityCheckTrait; use Drupal\cloud\Form\CloudContentForm; @@ -377,8 +377,10 @@ class AwsCloudContentForm extends CloudContentForm { * The AWS Cloud resource ID. */ protected function updateNameAndCreatedByTags(EntityInterface $entity, $aws_cloud_resource_id): void { + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $entity->getCloudContext()); $this->setTagsInAws($aws_cloud_resource_id, [ - $entity->getEntityTypeId() . '_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID => !empty($entity->getOwner()) + $entity->getEntityTypeId() . '_' . $uid_key_name => !empty($entity->getOwner()) ? $entity->getOwner()->id() : 0, 'Name' => $entity->getName(), ]); diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php index 8397934ef6746cbd76f7954a58f3096810397be5..7261a02d00729ce5ac3afac8cc334c69ba04e9e8 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Datetime\Entity\DateFormat; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; use Drupal\Core\Url; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\ElasticIp; use Drupal\aws_cloud\Entity\Ec2\Instance; use Drupal\aws_cloud\Entity\Ec2\PublicIpEntityLinkHtmlGenerator; @@ -758,10 +759,14 @@ class InstanceEditForm extends AwsCloudContentForm { }); $module_name = $this->getModuleName($entity); + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $entity->getCloudContext(), + Instance::TAG_LAUNCHED_BY_UID + ); $fixed_tags = []; $fixed_tags['Name'] = $entity->getName(); - $fixed_tags[$module_name . '_' . Instance::TAG_LAUNCHED_BY_UID] = $entity->getOwner() === NULL + $fixed_tags[$module_name . '_' . $uid_key_name] = $entity->getOwner() === NULL ? '' : $entity->getOwner()->id(); diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairCreateForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairCreateForm.php index 7b4265224a7c14dc24f3104c02c2f5512cc3fa78..4e517833bf19374bfb95c2b27a81e0c7de29aa39 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairCreateForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairCreateForm.php @@ -2,7 +2,7 @@ namespace Drupal\aws_cloud\Form\Ec2; -use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\cloud\Traits\CloudContentEntityTrait; use Drupal\Core\Form\FormStateInterface; @@ -76,6 +76,8 @@ class KeyPairCreateForm extends AwsCloudContentForm { /** @var \Drupal\aws_cloud\Entity\Ec2\KeyPair $entity */ $entity = $this->entity; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $entity->getCloudContext()); $result = $this->ec2Service->createKeyPair([ 'KeyName' => $entity->getKeyPairName(), @@ -84,7 +86,7 @@ class KeyPairCreateForm extends AwsCloudContentForm { 'ResourceType' => 'key-pair', 'Tags' => [ [ - 'Key' => $entity->getEntityTypeId() . '_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID, + 'Key' => $entity->getEntityTypeId() . '_' . $uid_key_name, 'Value' => !empty($entity->getOwner()) ? $entity->getOwner()->id() : 0, ], ], diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairEditForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairEditForm.php index e2c822160fe6ed44fce51341f727789bcdc0c48a..d9b023f6d624bbe0b5b3a0f57260ffc4a9a12d59 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairEditForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairEditForm.php @@ -2,7 +2,7 @@ namespace Drupal\aws_cloud\Form\Ec2; -use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\Core\Form\FormStateInterface; /** @@ -84,12 +84,14 @@ class KeyPairEditForm extends AwsCloudContentForm { $this->trimTextfields($form, $form_state); $entity = $this->entity; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $entity->getCloudContext()); $this->ec2Service->setCloudContext($entity->getCloudContext()); if ($entity->save()) { $this->setTagsInAws($entity->getKeyPairId(), [ - $entity->getEntityTypeId() . '_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID => !empty($entity->getOwner()) + $entity->getEntityTypeId() . '_' . $uid_key_name => !empty($entity->getOwner()) ? $entity->getOwner()->id() : 0, ]); } diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairImportForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairImportForm.php index 96b77d1fb31f285c629f241ba217e2bb94c2be88..e436168fe11c00c4585fd8abf0704c9b8bd157d6 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairImportForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/KeyPairImportForm.php @@ -2,7 +2,7 @@ namespace Drupal\aws_cloud\Form\Ec2; -use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\Language; @@ -108,6 +108,8 @@ class KeyPairImportForm extends AwsCloudContentForm { /** @var \Drupal\aws_cloud\Entity\Ec2\KeyPair $entity */ $entity = $this->entity; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $entity->getCloudContext()); if ($path = $form_state->getValue('key_pair_public_key')) { $handle = fopen($path, 'r'); @@ -122,7 +124,7 @@ class KeyPairImportForm extends AwsCloudContentForm { 'ResourceType' => 'key-pair', 'Tags' => [ [ - 'Key' => $entity->getEntityTypeId() . '_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID, + 'Key' => $entity->getEntityTypeId() . '_' . $uid_key_name, 'Value' => !empty($entity->getOwner()) ? $entity->getOwner()->id() : 0, ], ], diff --git a/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/FieldWidget/TagItem.php b/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/FieldWidget/TagItem.php index 6cd1c7065ac97a0f5a40f9b782ed38c407a3f723..bcbdb8f4851fa989cd250996d3c1145d7db83001 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/FieldWidget/TagItem.php +++ b/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/FieldWidget/TagItem.php @@ -112,6 +112,16 @@ class TagItem extends WidgetBase implements ContainerFactoryPluginInterface { $disabled = TRUE; } + // Reserve for cloud_server_template_*__uuid__context tags. + if ($key !== NULL && preg_match('/^cloud_server_template_+[a-z_]+__+[a-z0-9-]+__+[a-z0-9_]+$/', $key)) { + return TRUE; + } + + // Reserve for aws_cloud_*__uuid__context tags. + if ($key !== NULL && preg_match('/^aws_cloud_+[a-z_]+__+[a-z0-9-]+__+[a-z0-9_]+$/', $key)) { + return TRUE; + } + $element['tag_key'] = [ '#type' => 'textfield', '#title' => $this->t('Key'), diff --git a/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/Util/AwsCloudReservedKeyChecker.php b/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/Util/AwsCloudReservedKeyChecker.php index 4c446336a4c4704f420900fdb933608d2e495ddf..366407b3110141ff74850d29f5057cd8e00a1db8 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/Util/AwsCloudReservedKeyChecker.php +++ b/modules/cloud_service_providers/aws_cloud/src/Plugin/Field/Util/AwsCloudReservedKeyChecker.php @@ -44,6 +44,16 @@ class AwsCloudReservedKeyChecker implements ReservedKeyCheckerInterface { if ($key !== NULL && preg_match('/^launch_template_[a-z_]+$/', $key)) { return TRUE; } + + // Reserve for cloud_server_template_*__uuid__context tags. + if ($key !== NULL && preg_match('/^cloud_server_template_+[a-z_]+__+[a-z0-9-]+__+[a-z0-9_]+$/', $key)) { + return TRUE; + } + + // Reserve for aws_cloud_*__uuid__context tags. + if ($key !== NULL && preg_match('/^aws_cloud_+[a-z_]+__+[a-z0-9-]+__+[a-z0-9_]+$/', $key)) { + return TRUE; + } return FALSE; } diff --git a/modules/cloud_service_providers/aws_cloud/src/Plugin/cloud/server_template/AwsCloudServerTemplatePlugin.php b/modules/cloud_service_providers/aws_cloud/src/Plugin/cloud/server_template/AwsCloudServerTemplatePlugin.php index 57895b656bb2b1e7b3e8916a4500bf710121b39f..632a64f4e7635197db75abea655f2901b906832c 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Plugin/cloud/server_template/AwsCloudServerTemplatePlugin.php +++ b/modules/cloud_service_providers/aws_cloud/src/Plugin/cloud/server_template/AwsCloudServerTemplatePlugin.php @@ -2,9 +2,10 @@ namespace Drupal\aws_cloud\Plugin\cloud\server_template; -use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\Instance; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; +use Drupal\cloud\Entity\CloudServerTemplate; use Drupal\cloud\Entity\CloudServerTemplateInterface; use Drupal\cloud\Plugin\cloud\CloudPluginBase; use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface; @@ -265,6 +266,9 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe // Add tags from the template. foreach ($cloud_server_template->get('field_tags') ?: [] as $tag_item) { + if (strpos($tag_item->getItemKey, CloudServerTemplate::TAG_CREATED_BY_UID) !== FALSE) { + continue; + } $tags_map[$tag_item->getItemKey()] = $tag_item->getItemValue(); } @@ -674,7 +678,7 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe $name = $cloud_config->get('field_default_vpc_name')->value; $name = str_replace('[user_name]', $this->currentUser->getAccountName(), $name); - $vpc_id = $this->createVpc($cidr_block, $name); + $vpc_id = $this->createVpc($cidr_block, $name, $cloud_context); } if ($vpc_id === NULL) { @@ -692,9 +696,11 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe ]; $result = $this->ec2Service->describeSubnets($params); $subnet_id = NULL; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context); foreach ($result['Subnets'] ?: [] as $subnet) { foreach ($subnet['Tags'] ?: [] as $tag) { - if ($tag['Key'] === 'aws_cloud_subnet_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID && $tag['Value'] === $current_uid) { + if ($tag['Key'] === 'aws_cloud_subnet_' . $uid_key_name && $tag['Value'] === $current_uid) { $subnet_id = $subnet['SubnetId']; break; } @@ -712,7 +718,7 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe $name = $cloud_config->get('field_default_subnet_name')->value; $name = str_replace('[user_name]', $this->currentUser->getAccountName(), $name); - $subnet_id = $this->createSubnet($vpc_id, $subnet_cidr_block, $name); + $subnet_id = $this->createSubnet($vpc_id, $subnet_cidr_block, $name, $cloud_context); if ($subnet_id === NULL) { return [NULL, NULL]; @@ -752,11 +758,13 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe * The CIDR block. * @param string $name * The VPC name. + * @param string $cloud_context + * The cloud context. * * @return string * The ID of the VPC created. */ - private function createVpc($cidr_block, $name) { + private function createVpc($cidr_block, $name, $cloud_context): ?string { $result = $this->ec2Service->createVpc([ 'CidrBlock' => $cidr_block, ]); @@ -769,12 +777,14 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe } $vpc_id = $result['Vpc']['VpcId']; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context); $this->ec2Service->createTags([ 'Resources' => [$vpc_id], 'Tags' => [ [ - 'Key' => 'aws_cloud_vpc_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID, + 'Key' => 'aws_cloud_vpc_' . $uid_key_name, 'Value' => $this->currentUser->id(), ], [ @@ -804,7 +814,7 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe 'Resources' => [$security_group_id], 'Tags' => [ [ - 'Key' => 'aws_cloud_security_group_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID, + 'Key' => 'aws_cloud_security_group_' . $uid_key_name, 'Value' => $this->currentUser->id(), ], ], @@ -825,11 +835,13 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe * The CIDR block of the subnet. * @param string $name * The subnet name. + * @param string $cloud_context + * The cloud context. * * @return string * The ID of the subnet created. */ - private function createSubnet($vpc_id, $cidr_block, $name) { + private function createSubnet($vpc_id, $cidr_block, $name, $cloud_context): ?string { $result = $this->ec2Service->createSubnet([ 'VpcId' => $vpc_id, 'CidrBlock' => $cidr_block, @@ -843,11 +855,13 @@ class AwsCloudServerTemplatePlugin extends CloudPluginBase implements CloudServe } $subnet_id = $result['Subnet']['SubnetId']; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context); $result = $this->ec2Service->createTags([ 'Resources' => [$subnet_id], 'Tags' => [ [ - 'Key' => 'aws_cloud_subnet_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID, + 'Key' => 'aws_cloud_subnet_' . $uid_key_name, 'Value' => $this->currentUser->id(), ], [ diff --git a/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2BatchOperations.php b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2BatchOperations.php index c3675cc0af34bfc55d67d23de977090ada6a79c6..fec73c8d932343cdeb589fb2c3214a13c31433f3 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2BatchOperations.php +++ b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2BatchOperations.php @@ -2,6 +2,7 @@ namespace Drupal\aws_cloud\Service\Ec2; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\ElasticIp; use Drupal\aws_cloud\Entity\Ec2\Image; use Drupal\aws_cloud\Entity\Ec2\Instance; @@ -79,6 +80,10 @@ class Ec2BatchOperations { $termination_timestamp = NULL; $schedule = ''; $tags = []; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context, + Instance::TAG_LAUNCHED_BY_UID + ); if (!isset($instance['Tags'])) { $instance['Tags'] = []; } @@ -86,7 +91,7 @@ class Ec2BatchOperations { if ($tag['Key'] === 'Name') { $instanceName = $tag['Value']; } - if ($tag['Key'] === 'aws_cloud_' . Instance::TAG_LAUNCHED_BY_UID) { + if ($tag['Key'] === 'aws_cloud_' . $uid_key_name) { $uid = $tag['Value']; } if ($tag['Key'] === 'aws_cloud_' . Instance::TAG_TERMINATION_TIMESTAMP) { @@ -1546,6 +1551,9 @@ class Ec2BatchOperations { } $uid = 0; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $revision->getCloudContext(), + CloudServerTemplate::TAG_CREATED_BY_UID); foreach ($tags ?: [] as $tag) { $name = $tag['Key']; $value = $tag['Value']; @@ -1560,7 +1568,7 @@ class Ec2BatchOperations { continue; } - if ($name === CloudServerTemplate::TAG_CREATED_BY_UID) { + if ($name === $uid_key_name) { $uid = $value; continue; } diff --git a/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php index fa9f31ee74698c556fafab7bc1f4443b4788f249..89a42927272c093369efe154ce772bf0ec80a871 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php +++ b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php @@ -12,6 +12,7 @@ use Aws\MockHandler; use Aws\Result; use Aws\ResultInterface; use Aws\Sts\StsClient; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; use Drupal\aws_cloud\Entity\Ec2\Instance; use Drupal\cloud\Entity\CloudConfigInterface; @@ -1109,6 +1110,10 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface { */ public function runInstances(array $params = [], array $tags = []) { $params += $this->getDefaultParameters(); + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $this->cloudContext, + Instance::TAG_LAUNCHED_BY_UID + ); // Add meta tags to identify where the instance was launched from. $params['TagSpecifications'] = [ @@ -1128,7 +1133,7 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface { 'Value' => $this->currentUser->getAccountName(), ], [ - 'Key' => 'aws_cloud_' . Instance::TAG_LAUNCHED_BY_UID, + 'Key' => 'aws_cloud_' . $uid_key_name, 'Value' => $this->currentUser->id(), ], ], @@ -3742,7 +3747,17 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface { * {@inheritdoc} */ public function getUidTagValue(array $tags_array, $entity_type_id) { - $key = $entity_type_id . '_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID; + $key = ''; + + if (strpos($entity_type_id, 'aws_cloud') !== FALSE) { + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $this->cloudContext); + $key = $entity_type_id . '_' . $uid_key_name; + } + else { + $key = $entity_type_id . '_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID; + } + $uid = 0; if (!empty($tags_array['Tags'])) { foreach ($tags_array['Tags'] ?: [] as $tag) { diff --git a/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/Ec2/InstanceTest_instance_multi_uid.yml b/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/Ec2/InstanceTest_instance_multi_uid.yml new file mode 100644 index 0000000000000000000000000000000000000000..b312fe726405b6e13c3d60bd0299c41f69b00b93 --- /dev/null +++ b/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/Ec2/InstanceTest_instance_multi_uid.yml @@ -0,0 +1,38 @@ +# This is a supplemental YAML file for 'InstanceExtraTest.yml'. +InstanceId: '{{instance_id}}' +InstanceType: t3.micro +Placement: + AvailabilityZone: us-west-1c + Tenancy: default + GroupName: '{{group_name}}' + HostId: '{{host_id}}' + Affinity: '{{affinity}}' +LaunchTime: '{{launch_time}}' +Tags: + - Key: Name + Value: '{{name}}' + - Key: 'aws_cloud_instance_launched_by_uid__{{site_uuid}}__{{cloud_context}}' + Value: '{{uid}}' +SecurityGroups: + - GroupId: '{{security_group_id}}' + GroupName: '{{security_group_name}}' +State: + Code: 16 + Name: '{{state}}' +PublicDnsName: '{{public_dns_name}}' +PublicIpAddress: '{{public_ip_address}}' +PrivateDnsName: '{{private_dns_name}}' +PrivateIpAddress: '{{private_ip_address}}' +KeyName: '{{key_name}}' +Monitoring: + State: enabled +VpcId: '{{vpc_id}}' +SubnetId: '{{subnet_id}}' +SourceDestCheck: false +EbsOptimized: false +RootDeviceType: ebs +RootDeviceName: /dev/xvda +ImageId: '{{image_id}}' +VirtualizationType: hvm +AmiLaunchIndex: 0 +StateTransitionReason: '{{reason}}' diff --git a/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/Ec2/VolumeTest.yml b/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/Ec2/VolumeTest.yml index 3af23ebb13bfc009b7a5950288b2f269eae5ea89..0debd4e3c240651dd5633241ba560ca3101b74ef 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/Ec2/VolumeTest.yml +++ b/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/Ec2/VolumeTest.yml @@ -3,7 +3,7 @@ CreateVolume: CreateTime: '{{create_time}}' State: creating Tags: - - Key: aws_cloud_volume_created_by_uid + - Key: 'aws_cloud_volume_created_by_uid__{{site_uuid}}__{{cloud_context}}' Value: '{{uid}}' DescribeVolumes: diff --git a/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/cloud/config/AwsCloudConfigTest.yml b/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/cloud/config/AwsCloudConfigTest.yml index b6284af197d3066a05619ef464c7d47a5a3cab70..28b23a289f640b14d18cd1955834f2b8e1f9c45f 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/cloud/config/AwsCloudConfigTest.yml +++ b/modules/cloud_service_providers/aws_cloud/tests/mock_data/Functional/cloud/config/AwsCloudConfigTest.yml @@ -32,4 +32,4 @@ RevokeSecurityGroupIngress: [] # IAM API. ListInstanceProfiles: [] # CloudWatch API. -GetMetricData: [] \ No newline at end of file +GetMetricData: [] diff --git a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/ElasticIpTest.php b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/ElasticIpTest.php index b36d09436559bfbc17cd91d461314330b79b6b85..4061190a4e4d4fb00e05b26e296e53b7f9cceb83 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/ElasticIpTest.php +++ b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/ElasticIpTest.php @@ -114,7 +114,7 @@ class ElasticIpTest extends AwsCloudTestBase { // Delete Elastic IP where no Mock data is empty. // Should redirect and show error message. // 3 times. - $this->updateInstanceMockData(InstanceTest::class, 0, '', $regions); + $this->updateInstanceMockData(InstanceTest::class, 0, '', $regions, 'stopped', $cloud_context); $this->deleteAllElasticIpInMockData(); for ($i = 0, $num = 1; $i < self::AWS_CLOUD_ELASTIC_IP_REPEAT_COUNT; $i++, $num++) { @@ -197,7 +197,7 @@ class ElasticIpTest extends AwsCloudTestBase { // Setup a test instance. $instance_id = 'i-' . $this->getRandomId(); $instance = $this->createInstanceTestEntity(Instance::class, $j, $regions, $elastic_ip['PublicIp'], $instance_id); - $instance_id = $this->addInstanceMockData(InstanceTest::class, $instance->getName(), $instance->getKeyPairName(), $regions); + $instance_id = $this->addInstanceMockData(InstanceTest::class, $instance->getName(), $instance->getKeyPairName(), $regions, 'running', '', $cloud_context); // Setup a test network interface. $this->createNetworkInterfaceTestEntity(NetworkInterface::class, $j, '', '', $instance_id); @@ -300,7 +300,7 @@ class ElasticIpTest extends AwsCloudTestBase { // Setup a test instance. $instance_id = 'i-' . $this->getRandomId(); $instance = $this->createInstanceTestEntity(Instance::class, $j, $regions, $elastic_ip['PublicIp'], $instance_id); - $this->addInstanceMockData(InstanceTest::class, $instance->getName(), $instance->getKeyPairName(), $regions); + $this->addInstanceMockData(InstanceTest::class, $instance->getName(), $instance->getKeyPairName(), $regions, 'running', '', $cloud_context); // Setup a test network interface. $this->createNetworkInterfaceTestEntity(NetworkInterface::class, $j, '', '', $instance_id); diff --git a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceExtraTest.php b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceExtraTest.php index 5f04c31d5380c09073f8589bb8eaafb95e1e83e9..357a33282aa7f2033e688a3d639e2c75c195457a 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceExtraTest.php +++ b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceExtraTest.php @@ -136,7 +136,7 @@ class InstanceExtraTest extends AwsCloudTestBase { $this->assertSession()->pageTextContains($server_template->name->value); // Launch a stopped Instance. - $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'stopped'); + $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'stopped', '', $cloud_context); $this->drupalGet("/clouds/design/server_template/$cloud_context/$num/launch"); $this->submitForm( [], @@ -171,7 +171,7 @@ class InstanceExtraTest extends AwsCloudTestBase { $edit[$i], $this->t('Save')); - $this->updateInstanceMockData(InstanceTest::class, $i, $edit[$i]['name'], $regions); + $this->updateInstanceMockData(InstanceTest::class, $i, $edit[$i]['name'], $regions, 'stopped', $cloud_context); $this->assertNoErrorMessage(); $t_args = ['@type' => 'Instance', '%label' => $edit[$i]['name']]; @@ -322,7 +322,7 @@ class InstanceExtraTest extends AwsCloudTestBase { $this->assertNoErrorMessage(); $this->assertSession()->pageTextContains($server_template->name->value); - $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'running', $schedule_value); + $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'running', $schedule_value, $cloud_context); $this->drupalGet("/clouds/design/server_template/$cloud_context/$num/launch"); $this->submitForm( diff --git a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceTest.php b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceTest.php index 5908d56e64b52d16efd022f70e3f3dd54c682de1..03f285b707a0f04ebddacb9227852e5798f11e03 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceTest.php +++ b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceTest.php @@ -145,7 +145,7 @@ class InstanceTest extends AwsCloudTestBase { $this->assertNoErrorMessage(); $this->assertSession()->pageTextContains($server_template->name->value); - $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions); + $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'running', '', $cloud_context); $this->drupalGet("/clouds/design/server_template/${cloud_context}/{$server_template->id()}/launch"); $this->submitForm( [], @@ -198,7 +198,7 @@ class InstanceTest extends AwsCloudTestBase { $edit[$i]['termination_timestamp[0][value][date]'] = date('Y-m-d', time() + 365.25 * 3); $edit[$i]['termination_timestamp[0][value][time]'] = '00:00:00'; $edit[$i]['termination_protection'] = '1'; - $this->updateInstanceMockData(InstanceTest::class, $i, $edit[$i]['name'], $regions); + $this->updateInstanceMockData(InstanceTest::class, $i, $edit[$i]['name'], $regions, 'stopped', $cloud_context); // IAM role. $iam_role_index = array_rand($iam_roles); if ($iam_role_index === 0) { @@ -318,7 +318,7 @@ class InstanceTest extends AwsCloudTestBase { $this->assertNoErrorMessage(); $this->assertSession()->pageTextContains($server_template->name->value); - $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions); + $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'running', '', $cloud_context); $this->drupalGet("/clouds/design/server_template/${cloud_context}/{$server_template->id()}/launch"); $this->submitForm( [], @@ -381,7 +381,7 @@ class InstanceTest extends AwsCloudTestBase { $this->assertSession()->pageTextContains($server_template->name->value); // Launch a new Instance. - $this->addInstanceMockData(InstanceTest::class, $add[0]['name'], $add[0]['key_pair_name'], $regions); + $this->addInstanceMockData(InstanceTest::class, $add[0]['name'], $add[0]['key_pair_name'], $regions, 'running', '', $cloud_context); $this->drupalGet("/clouds/design/server_template/$cloud_context/1/launch"); $this->submitForm( [], @@ -527,7 +527,7 @@ class InstanceTest extends AwsCloudTestBase { // Create Instances in mock data. for ($i = 0, $num = 1; $i < self::AWS_CLOUD_INSTANCE_REPEAT_COUNT; $i++, $num++) { - $instance_id = $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions); + $instance_id = $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'running', '', $cloud_context); $add[$i]['instance_id'] = $instance_id; } @@ -587,7 +587,7 @@ class InstanceTest extends AwsCloudTestBase { // Change Instance Name in mock data. $add[$i]['name'] = sprintf('instance-entity #%d - %s - %s', $num, date('Y/m/d H:i:s'), $this->random->name(8, TRUE)); - $this->updateInstanceMockData(InstanceTest::class, $i, $add[$i]['name'], $regions); + $this->updateInstanceMockData(InstanceTest::class, $i, $add[$i]['name'], $regions, 'stopped', $cloud_context); } @@ -770,7 +770,7 @@ class InstanceTest extends AwsCloudTestBase { $this->assertNoErrorMessage(); $this->assertSession()->pageTextContains($server_template->name->value); - $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions); + $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'running', '', $cloud_context); $this->drupalGet("/clouds/design/server_template/${cloud_context}/{$server_template->id()}/launch"); $this->submitForm( [], @@ -784,9 +784,9 @@ class InstanceTest extends AwsCloudTestBase { } // Create Instances in mock data. - for ($i = 0, $num = 1; $i < self::AWS_CLOUD_INSTANCE_REPEAT_COUNT; $i++, $num++) { - $instance_id = $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions); - $add[$i]['instance_id'] = $instance_id; + for ($j = 0; $j < self::AWS_CLOUD_INSTANCE_REPEAT_COUNT; $j++) { + $instance_id = $this->addInstanceMockData(InstanceTest::class, $add[$j]['name'], $add[$j]['key_pair_name'], $regions, 'running', '', $cloud_context); + $add[$j]['instance_id'] = $instance_id; } } } @@ -849,7 +849,7 @@ class InstanceTest extends AwsCloudTestBase { // Change Instance Name in mock data. $add[$i]['name'] = sprintf('instance-entity #%d - %s - %s', $num, date('Y/m/d H:i:s'), $this->random->name(8, TRUE)); - $this->updateInstanceMockData(InstanceTest::class, $i, $add[$i]['name'], $regions); + $this->updateInstanceMockData(InstanceTest::class, $i, $add[$i]['name'], $regions, 'stopped', $cloud_context); } } @@ -930,7 +930,7 @@ class InstanceTest extends AwsCloudTestBase { $this->assertNoErrorMessage(); $this->assertSession()->pageTextContains($server_template->name->value); - $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions); + $this->addInstanceMockData(InstanceTest::class, $add[$i]['name'], $add[$i]['key_pair_name'], $regions, 'running', '', $cloud_context); $this->drupalGet("/clouds/design/server_template/$cloud_context/{$server_template->id()}/launch"); $this->submitForm( [], diff --git a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeAttachDetachTest.php b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeAttachDetachTest.php index 281088166e1682d87cdfb093c745846ea89aaf4e..9f00d8dce3267d1ce66b747ed53b1c04041c0e24 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeAttachDetachTest.php +++ b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeAttachDetachTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\aws_cloud\Functional\Ec2; -use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\Instance; use Drupal\aws_cloud\Entity\Ec2\Volume; use Drupal\Tests\aws_cloud\Functional\AwsCloudTestBase; @@ -68,6 +68,8 @@ class VolumeAttachDetachTest extends AwsCloudTestBase { $regions = ['us-west-1', 'us-west-2']; $add = $this->createVolumeTestFormData($max_test_repeat_count + 1); + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $this->cloudContext); for ($i = 1; $i <= $max_test_repeat_count; $i++) { // Setup for testing. $device_name = $this->random->name(8, TRUE); @@ -88,7 +90,7 @@ class VolumeAttachDetachTest extends AwsCloudTestBase { $volume_id = $volume->getVolumeId(); $add[$i]['VolumeId'] = $volume_id; $add[$i]['name'] = $volume->getName(); - $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID); + $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . $uid_key_name); $attach_data = [ 'device_name' => $device_name, @@ -137,6 +139,8 @@ class VolumeAttachDetachTest extends AwsCloudTestBase { $total_count = 0; $total_volumes = []; $regions = ['us-west-1', 'us-west-2']; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context); // NOTE: $num needs to be incremented outside $j loop. for ($i = 0, $num = 1; $i < self::MAX_TEST_REPEAT_COUNT; $i++) { @@ -152,7 +156,7 @@ class VolumeAttachDetachTest extends AwsCloudTestBase { // Setup a test instance. $instance = $this->createInstanceTestEntity(Instance::class, $j, $regions); $instance_id = $instance->getInstanceId(); - $this->addInstanceMockData(InstanceTest::class, $instance->getName(), $instance->getKeyPairName(), $regions); + $this->addInstanceMockData(InstanceTest::class, $instance->getName(), $instance->getKeyPairName(), $regions, 'running', '', $cloud_context); // Setup a test volume. $volume = $this->createVolumeTestEntity( @@ -164,7 +168,7 @@ class VolumeAttachDetachTest extends AwsCloudTestBase { $this->loggedInUser->id() ); $volume_id = $volume->getVolumeId(); - $this->addVolumeMockData($volumes[$j], 'aws_cloud_volume_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID); + $this->addVolumeMockData($volumes[$j], 'aws_cloud_volume_' . $uid_key_name); $attach_data = [ 'device_name' => $device_name, diff --git a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeTest.php b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeTest.php index aa542c7964e0c6b02da9a5fc0ac9d41e9630672d..b535596613e2680fac215c8cc885fb76388e790f 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeTest.php +++ b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/VolumeTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\aws_cloud\Functional\Ec2; -use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntityInterface; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\Instance; use Drupal\aws_cloud\Entity\Ec2\Snapshot; use Drupal\aws_cloud\Entity\Ec2\Volume; @@ -44,6 +44,8 @@ class VolumeTest extends AwsCloudTestBase { 'volume_id' => 'vol-' . $this->getRandomId(), 'create_time' => date('c'), 'uid' => Utils::getRandomUid(), + 'site_uuid' => \Drupal::config('system.site')->get('uuid'), + 'cloud_context' => $this->cloudContext, ]; } @@ -116,7 +118,9 @@ class VolumeTest extends AwsCloudTestBase { $this->assertSession()->pageTextContains($add[$i]['snapshot_id']); $this->assertSession()->pageTextContains($snapshot_name); $add[$i]['VolumeId'] = $volume_id; - $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID); + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context); + $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . $uid_key_name); } for ($i = 0, $num = 1; $i < self::AWS_CLOUD_VOLUME_REPEAT_COUNT; $i++, $num++) { @@ -191,11 +195,13 @@ class VolumeTest extends AwsCloudTestBase { public function testUpdateVolumeList(): void { $cloud_context = $this->cloudContext; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context); // Add a new Volume. $add = $this->createVolumeTestFormData(self::AWS_CLOUD_VOLUME_REPEAT_COUNT); for ($i = 0; $i < self::AWS_CLOUD_VOLUME_REPEAT_COUNT; $i++) { - $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID); + $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . $uid_key_name); $snapshot_name = 'snapshot-name' . $this->random->name(10, TRUE); $this->createSnapshotTestEntity(Snapshot::class, $i, $add[$i]['snapshot_id'], $snapshot_name, $cloud_context); } @@ -381,18 +387,19 @@ class VolumeTest extends AwsCloudTestBase { $this->assertNoErrorMessage(); // Create Cloud Config. + $this->cloudContext = $this->random->name(8); for ($i = 0; $i < self::AWS_CLOUD_VOLUME_REPEAT_COUNT; $i++) { - $this->cloudContext = $this->random->name(8); $cloud_config = $this->createCloudConfigTestEntity($this->cloudContext); $cloud_configs[] = $cloud_config; } foreach ($cloud_configs ?: [] as $cloud_config) { $cloud_context = $cloud_config->getCloudContext(); + $uid_key_name = AwsCloudEntity::getTagCreatedByUid($cloud_context); // Add a new Volume. $add = $this->createVolumeTestFormData(self::AWS_CLOUD_VOLUME_REPEAT_COUNT); for ($i = 0; $i < self::AWS_CLOUD_VOLUME_REPEAT_COUNT; $i++) { - $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID); + $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . $uid_key_name); $snapshot_name = "snapshot-name{$this->random->name(10, TRUE)}"; $this->createSnapshotTestEntity(Snapshot::class, $i, $add[$i]['snapshot_id'], $snapshot_name, $cloud_context); } @@ -528,6 +535,8 @@ class VolumeTest extends AwsCloudTestBase { */ private function repeatTestCreateSnapshotOperation($max_count): void { $cloud_context = $this->cloudContext; + $uid_key_name = AwsCloudEntity::getTagCreatedByUid( + $cloud_context); $add = $this->createVolumeTestFormData(self::AWS_CLOUD_VOLUME_REPEAT_COUNT); for ($i = 0; $i < $max_count; $i++) { @@ -556,7 +565,7 @@ class VolumeTest extends AwsCloudTestBase { // Add a volume to DescribeVolumes. $volume_id = $this->latestTemplateVars['volume_id']; $add[$i]['name'] = $volume_id; - $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . AwsCloudEntityInterface::TAG_CREATED_BY_UID); + $this->addVolumeMockData($add[$i], 'aws_cloud_volume_' . $uid_key_name); // Click "Create Snapshot" link. $this->clickLink($this->t('Create Snapshot'), $i); diff --git a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/cloud/server_template/CloudServerTemplateTest.php b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/cloud/server_template/CloudServerTemplateTest.php index bb96454809b94effcb87a9ddbaefc14271809da9..a83087149c5c5b6b614c5bd60751190f7c258f8e 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/src/Functional/cloud/server_template/CloudServerTemplateTest.php +++ b/modules/cloud_service_providers/aws_cloud/tests/src/Functional/cloud/server_template/CloudServerTemplateTest.php @@ -2,10 +2,12 @@ namespace Drupal\Tests\aws_cloud\Functional\cloud\server_template; +use Drupal\aws_cloud\Entity\Ec2\AwsCloudEntity; use Drupal\aws_cloud\Entity\Ec2\Image; use Drupal\aws_cloud\Entity\Ec2\KeyPair; use Drupal\aws_cloud\Entity\Ec2\SecurityGroup; use Drupal\cloud\Entity\CloudContentEntityBase; +use Drupal\cloud\Entity\CloudServerTemplate; use Drupal\cloud\Entity\CloudServerTemplateInterface; use Drupal\Tests\aws_cloud\Functional\AwsCloudTestBase; use Drupal\Tests\cloud\Traits\CloudServerTemplateTrait; @@ -180,6 +182,11 @@ class CloudServerTemplateTest extends AwsCloudTestBase { $this->assertSession()->pageTextContains($iam_role_name); $this->assertSession()->pageTextContains($add[$i]['field_tags[0][item_key]']); $this->assertSession()->pageTextContains($add[$i]['field_tags[0][item_value]']); + $this->assertSession()->pageTextContains( + AwsCloudEntity::getTagCreatedByUid( + $cloud_context, + CloudServerTemplate::TAG_CREATED_BY_UID + )); // Make sure listing. $this->drupalGet("/clouds/design/server_template/$cloud_context"); diff --git a/modules/cloud_service_providers/aws_cloud/tests/src/Traits/AwsCloudTestMockTrait.php b/modules/cloud_service_providers/aws_cloud/tests/src/Traits/AwsCloudTestMockTrait.php index 76ee400d8057135fa1490058c5ffe23519f40db2..e339549ab82ba99b3445dc3b4378936b1a27f27e 100644 --- a/modules/cloud_service_providers/aws_cloud/tests/src/Traits/AwsCloudTestMockTrait.php +++ b/modules/cloud_service_providers/aws_cloud/tests/src/Traits/AwsCloudTestMockTrait.php @@ -106,13 +106,15 @@ trait AwsCloudTestMockTrait { * Instance state. * @param string $schedule_value * Schedule value. + * @param string $cloud_context + * The cloud context. * * @return string * The instance ID. * * @throws \Exception */ - protected function addInstanceMockData($test_class, $name = '', $key_pair_name = '', array $regions = [], $state = 'running', $schedule_value = ''): string { + protected function addInstanceMockData($test_class, $name = '', $key_pair_name = '', array $regions = [], $state = 'running', $schedule_value = '', $cloud_context = ''): string { // Prepare the mock data for an instance. $public_ip = Utils::getRandomPublicIp(); $private_ip = Utils::getRandomPrivateIp(); @@ -143,9 +145,18 @@ trait AwsCloudTestMockTrait { 'uid' => $this->loggedInUser->id(), ]; + $mock_data_suffix = '_instance'; + if (!empty($cloud_context)) { + $mock_data_suffix = '_instance_multi_uid'; + $vars = array_merge($vars, [ + 'site_uuid' => \Drupal::config('system.site')->get('uuid'), + 'cloud_context' => $cloud_context, + ]); + } + $vars = array_merge($this->getMockDataTemplateVars(), $vars); - $instance_mock_data_content = $this->getMockDataFileContent($test_class, $vars, '_instance'); + $instance_mock_data_content = $this->getMockDataFileContent($test_class, $vars, $mock_data_suffix); $instance_mock_data = Yaml::decode($instance_mock_data_content); // OwnerId and ReservationId need to be set. @@ -278,10 +289,12 @@ trait AwsCloudTestMockTrait { * The Regions. * @param string $state * Instance state. + * @param string $cloud_context + * The cloud context. * * @throws \Exception */ - protected function updateInstanceMockData($test_class, $index = 0, $name = '', array $regions = [], $state = 'stopped'): void { + protected function updateInstanceMockData($test_class, $index = 0, $name = '', array $regions = [], $state = 'stopped', $cloud_context = ''): void { $mock_data = $this->getMockDataFromConfig(); if (empty($name)) { @@ -315,8 +328,17 @@ trait AwsCloudTestMockTrait { 'uid' => $this->loggedInUser->id(), ]; + $mock_data_suffix = '_instance'; + if (!empty($cloud_context)) { + $mock_data_suffix = '_instance_multi_uid'; + $vars = array_merge($vars, [ + 'site_uuid' => \Drupal::config('system.site')->get('uuid'), + 'cloud_context' => $cloud_context, + ]); + } + // Create a mock data for an Instance. - $instance_mock_data_content = $this->getMockDataFileContent($test_class, $vars, '_instance'); + $instance_mock_data_content = $this->getMockDataFileContent($test_class, $vars, $mock_data_suffix); $instance_mock_data = Yaml::decode($instance_mock_data_content); // OwnerId and ReservationId need to be set.