Skip to content
Snippets Groups Projects
Commit a30b5b3a authored by Yas Naoi's avatar Yas Naoi Committed by Yas Naoi
Browse files

Issue #3119973 by yas, baldwinlouie: Add test cases to install / uninstall...

Issue #3119973 by yas, baldwinlouie: Add test cases to install / uninstall modules for cloud, aws_cloud, k8s and openstack
parent 0162dd5c
No related branches found
Tags 8.x-1.2-beta2
No related merge requests found
Showing
with 215 additions and 51 deletions
......@@ -3,8 +3,14 @@ type: module
description: Allows users to manage Clouds.
package: Cloud
dependencies:
- drupal:views
- drupal:field
- drupal:file
- drupal:filter
- drupal:image
- drupal:options
- drupal:user
- drupal:text
- drupal:views
core : 8.x
scripts:
- js/cloud.js
......
......@@ -5,22 +5,22 @@
* Install and updates for aws_cloud.
*/
use Drupal\Core\Config\FileStorage;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\cloud\Entity\CloudServerTemplateType;
use Drupal\cloud\Entity\CloudServerTemplateTypeListBuilder;
use Drupal\cloud\Form\CloudServerTemplateTypeForm;
use Drupal\cloud\Form\CloudServerTemplateTypeDeleteForm;
use Drupal\cloud\Routing\CloudServerTemplateTypeHtmlRouteProvider;
use Drupal\cloud\Controller\CloudServerTemplateAccessControlHandler;
use Drupal\cloud\Controller\CloudServerTemplateListBuilder;
use Drupal\cloud\Entity\CloudServerTemplate;
use Drupal\cloud\Entity\CloudServerTemplateStorage;
use Drupal\cloud\Controller\CloudServerTemplateListBuilder;
use Drupal\cloud\Entity\CloudServerTemplateViewsData;
use Drupal\cloud\Entity\CloudServerTemplateTranslationHandler;
use Drupal\cloud\Form\CloudServerTemplateForm;
use Drupal\cloud\Entity\CloudServerTemplateType;
use Drupal\cloud\Entity\CloudServerTemplateTypeListBuilder;
use Drupal\cloud\Entity\CloudServerTemplateViewsData;
use Drupal\cloud\Form\CloudServerTemplateDeleteForm;
use Drupal\cloud\Controller\CloudServerTemplateAccessControlHandler;
use Drupal\cloud\Form\CloudServerTemplateForm;
use Drupal\cloud\Form\CloudServerTemplateTypeDeleteForm;
use Drupal\cloud\Form\CloudServerTemplateTypeForm;
use Drupal\cloud\Routing\CloudServerTemplateTypeHtmlRouteProvider;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Field\BaseFieldDefinition;
/**
* Removed obsolete cloud_pricing interrupts update from beta1 to beta2.
......@@ -399,8 +399,8 @@ function cloud_update_8122() {
$source = new FileStorage($config_path);
foreach ($fields ?: [] as $field) {
// Obtain the storage manager for field termination protection bases
// Create a new field from the yaml configuration and save.
// Obtain the storage manager for field_storage_config entity type, then
// create a new field from the yaml configuration and save.
\Drupal::entityTypeManager()->getStorage('field_storage_config')
->create($source->read("field.storage.cloud_config.$field"))
->save();
......@@ -518,14 +518,9 @@ function cloud_update_8127() {
* Add launch resources field to cloud_server_template.
*/
function cloud_update_8128() {
$config_path = realpath(drupal_get_path('module', 'cloud')) . '/config/install';
$source = new FileStorage($config_path);
// Obtain the storage manager for field termination protection bases
// Create a new field from the yaml configuration and save.
\Drupal::entityTypeManager()->getStorage('field_storage_config')
->create($source->read('field.storage.cloud_server_template.field_launch_resources'))
->save();
// Moved the field.storage.cloud_server_template.field_launch_resources.yml
// to k8s module.
// See also cloud_update_8131.
}
/**
......@@ -559,3 +554,12 @@ function cloud_update_8130() {
}
}
}
/**
* Remove launch resources field to cloud_server_template.
*/
function cloud_update_8131() {
\Drupal::configFactory()
->getEditable('field.storage.cloud_server_template.field_launch_resources')
->delete();
}
......@@ -28,7 +28,10 @@ use Drupal\views\ViewExecutable;
function cloud_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.cloud':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Cloud') . '</p>';
$output = '<p>' . t('The cloud module creates a user interface for users to manage clouds. Users can Create Instances, Describe Instances etc.') . '</p>';
$output .= '<p>' . t('For more information, see the <a href=":cloud_documentation">online documentation for the Cloud module</a>.', [':cloud_documentation' => 'https://www.drupal.org/docs/8/modules/cloud']) . '</p>';
return $output;
case 'help.page.cloud_server_template':
......@@ -36,6 +39,7 @@ function cloud_help($route_name, RouteMatchInterface $route_match) {
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Cloud server template') . '</p>';
$output .= '<p>' . t('The cloud_server_template module creates a user interface for users to manage clouds. Users can create cloud server templates.') . '</p>';
$output .= '<p>' . t('For more information, see the <a href=":cloud_documentation">online documentation for the Cloud module</a>.', [':cloud_documentation' => 'https://www.drupal.org/docs/8/modules/cloud']) . '</p>';
return $output;
default:
......@@ -175,10 +179,14 @@ function cloud_install_location_fields($bundle) {
continue;
}
// Obtain the storage manager for field_storage_config entity type, then
// create a new field from the yaml configuration and save.
\Drupal::entityTypeManager()->getStorage('field_storage_config')
->create($cloud_source->read("field.storage.cloud_config.${location_field}"))
->save();
// Obtain the storage manager for field_config entity type, then
// create a new field from the yaml configuration and save.
\Drupal::entityTypeManager()->getStorage('field_config')
->create($bundle_source->read("field.field.cloud_config.${bundle}.${location_field}"))
->save();
......@@ -217,6 +225,35 @@ function cloud_uninstall_location_fields($module_name, $bundle = NULL) {
}
}
/**
* Helper function to delete default icon.
*
* @param string $module
* The module name.
*/
function cloud_delete_default_icon($module) {
try {
// Delete default icon.
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable("${module}.settings");
$fid = !empty($config) ? $config->get("${module}_cloud_config_icon") : NULL;
// Delete file from disk and from database.
if (!empty($fid)) {
$storage = \Drupal::entityTypeManager()->getStorage('file');
$files = !empty($storage) ? $storage->loadMultiple([$fid]) : [];
$storage->delete($files);
}
}
catch (\Exception $e) {
// @TODO: Add error handling.
$error_message = "An error occurred: ${e}";
\Drupal::messenger()->addError($error_message);
\Drupal::logger('cloud')->error($error_message);
}
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
......
......@@ -2,7 +2,7 @@ langcode: en
status: true
dependencies:
module:
- cloud
- image
enforced:
module:
- cloud
......
......@@ -2,7 +2,7 @@ langcode: en
status: true
dependencies:
module:
- cloud
- image
enforced:
module:
- cloud
......
......@@ -2,7 +2,7 @@ langcode: en
status: true
dependencies:
module:
- cloud
- image
enforced:
module:
- cloud
......
......@@ -6,6 +6,23 @@
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function cloud_budget_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.cloud_budget':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The cloud budget module allows users to manage Cloud Budget.') . '</p>';
$output .= '<p>' . t('For more information, see the <a href=":cloud_documentation">online documentation for the Cloud Budget module</a>.', [':cloud_documentation' => 'https://www.drupal.org/docs/8/modules/cloud']) . '</p>';
return $output;
default:
return '';
}
}
/**
* Implements hook_form_alter().
......
<?php
namespace Drupal\Tests\cloud_budget\Functional\Module;
use Drupal\Tests\cloud\Functional\Module\CloudModuleTestBase;
/**
* Tests install / uninstall module(s) and confirm table creation/deletion.
*
* @group Cloud
*/
class CloudBudgetInstallUninstallTest extends CloudModuleTestBase {
/**
* Tests that a fixed set of modules can be installed and uninstalled.
*/
public function testInstallUninstall(): void {
$this->repeatAssertInstallUninstallModules(['cloud_budget']);
}
}
......@@ -35,6 +35,9 @@ function aws_cloud_uninstall() {
// @TODO: Delete the following user later on.
cloud_uninstall_service_provider('aws_ec2');
// Delete default icon.
cloud_delete_default_icon('aws_cloud');
// Delete cloud config fields.
// NOTE: field_location_* fields consists of two kinds of information
// such as field.field.cloud_config.aws_cloud.field_location_* and
......@@ -58,21 +61,21 @@ function aws_cloud_uninstall() {
*/
function aws_cloud_add_fields($entity_type, $bundle, $fields) {
$config_path = drupal_get_path('module', 'aws_cloud') . '/config/install';
$source = new FileStorage($config_path);
$source = new FileStorage($config_path);
if (!is_array($fields)) {
$fields = [$fields];
}
foreach ($fields ?: [] as $field) {
// Obtain the storage manager for field termination protection bases
// Create a new field from the yaml configuration and save.
// Obtain the storage manager for field_storage_config entity type, then
// create a new field from the yaml configuration and save.
\Drupal::entityTypeManager()->getStorage('field_storage_config')
->create($source->read("field.storage.$entity_type.$field"))
->save();
// Obtain the storage manager for field termination protection
// Create a new field IAM role from the yaml configuration and save.
// Obtain the storage manager for field_config entity type, then
// create a new field from the yaml configuration and save.
\Drupal::entityTypeManager()->getStorage('field_config')
->create($source->read("field.field.$entity_type.$bundle.$field"))
->save();
......@@ -2369,3 +2372,12 @@ function aws_cloud_update_8218() {
\Drupal::messenger()->addError("An error occurred: {$e}");
}
}
/**
* Change aws_cloud_config_icon to aws_cloud_cloud_config_icon.
*/
function aws_cloud_update_8219() {
// Creates 'aws_cloud_cloud_config_icon'.
cloud_add_default_icon('aws_cloud');
}
......@@ -34,6 +34,47 @@ use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Implements hook_help().
*/
function aws_cloud_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.aws_cloud':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('AWS Cloud (aws_cloud module) creates a user interface for managing AWS-related clouds. AWS Cloud is defined as Amazon EC2.') . '</p>';
$output .= '<h3>' . t('Features') . '</h3>';
$output .= '<ul>';
$output .= '<li>' . t('<strong>EC2</strong>');
$output .= '<ul>';
$output .= '<li>' . t('Manage EC2.') . '</li>';
$output .= '<li>' . t('Integrate with AWS Instance Scheduler.') . '</li>';
$output .= '<li>' . t('Support EC2 launch templates.') . '</li>';
$output .= '<li>' . t('Support automatic termination scheduling.') . '</li>';
$output .= '<li>' . t('Support instance profile (instance IAM role), assume role and switch role') . '</li>';
$output .= '</ul></li></ul>';
$output .= '<ul>';
$output .= '<li>' . t('<strong>VPC</strong>');
$output .= '<ul>';
$output .= '<li>' . t('Manage VPC.') . '</li>';
$output .= '<li>' . t('Create a VPC automatically based on each login user account.') . '</li>';
$output .= '<li>' . t('Create and manage bastion for each VPC.') . '</li>';
$output .= '<li>' . t('Support VPC flow logs.') . '</li>';
$output .= '<li>' . t('Support Cloud Formation templates to deploy a Cloud Orchestrator distribution.') . '</li>';
$output .= '</ul></li></ul>';
$output .= '<ul>';
$output .= '<li>' . t('<strong>Cost</strong>');
$output .= '<ul>';
$output .= '<li>' . t('List up instance type specs and costs.') . '</li>';
$output .= '<li>' . t('Create Google Spreadsheets for instance type specs and costs.') . '</li>';
$output .= '<li>' . t('Send reminder alerts for long-running instances, unused volumes and snapshots.') . '</li>';
$output .= '<li>' . t('Manage budgets and credits.') . '</li>';
$output .= '</ul></li></ul>';
$output .= '<p>' . t('For more information, see the <a href=":cloud_documentation">online documentation for the AWS Cloud module</a>.', [':cloud_documentation' => 'https://www.drupal.org/docs/8/modules/cloud']) . '</p>';
return $output;
}
}
/**
* Implements hook_libraries_info().
*/
......@@ -57,18 +98,6 @@ function aws_cloud_libraries_info() {
];
}
/**
* Implements hook_help().
*/
function aws_cloud_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.aws_cloud':
$output = '<p>' . t('The aws_cloud module creates a user interface for managing AWS related clouds. AWS Cloud is defined as Amazon EC2.') . '</p>';
return $output;
}
}
/**
* Set dynamic allowed values for the alignment field.
*
......@@ -547,7 +576,7 @@ function aws_cloud_default_cloud_config_icon(EntityInterface $entity) {
// Provides the calling hook with the default aws icon.
if ($entity->bundle() === 'aws_cloud') {
$config = \Drupal::config('aws_cloud.settings');
return $config->get('aws_cloud_config_icon');
return $config->get('aws_cloud_cloud_config_icon');
}
}
......@@ -2473,7 +2502,7 @@ function aws_cloud_form_cloud_config_aws_cloud_add_form_submit_finished(
function aws_cloud_form_cloud_config_aws_cloud_form_common_alter(array &$form, FormStateInterface $form_state, $form_id) {
// Set the default aws icon.
$config = \Drupal::config('aws_cloud.settings');
$default_image = $config->get('aws_cloud_config_icon');
$default_image = $config->get('aws_cloud_cloud_config_icon');
if ($default_image) {
try {
$file = File::load($default_image);
......@@ -4158,8 +4187,6 @@ function aws_cloud_cloud_config_fieldsets(array &$fields) {
$fields['new_revision']['#access'] = FALSE;
$fields['revision_log_message']['#access'] = FALSE;
$fields['#attached']['library'][] = 'aws_cloud/aws_cloud_config';
cloud_form_reorder($fields, $fieldset_defs);
}
......
langcode: en
status: true
dependencies: { }
dependencies:
module:
- cloud
enforced:
module:
- aws_cloud
id: aws_cloud
label: AWS Cloud
label: 'AWS Cloud'
langcode: en
status: true
dependencies: { }
dependencies:
module:
- cloud
enforced:
module:
- aws_cloud
id: aws_cloud
label: AWS Cloud
label: 'AWS Cloud'
......@@ -34,6 +34,11 @@ dependencies:
- field.field.cloud_config.aws_cloud.field_use_instance_profile
- field.field.cloud_config.aws_cloud.field_use_switch_role
- field.field.cloud_config.aws_cloud.field_x_509_certificate
module:
- cloud
enforced:
module:
- aws_cloud
id: cloud_config.aws_cloud.default
targetEntityType: cloud_config
bundle: aws_cloud
......
......@@ -25,6 +25,11 @@ dependencies:
- field.field.cloud_server_template.aws_cloud.field_iam_role
- field.field.cloud_server_template.aws_cloud.field_tags
- field.field.cloud_server_template.aws_cloud.field_version
module:
- cloud
enforced:
module:
- aws_cloud
id: cloud_server_template.aws_cloud.default
targetEntityType: cloud_server_template
bundle: aws_cloud
......
......@@ -35,8 +35,12 @@ dependencies:
- field.field.cloud_config.aws_cloud.field_use_switch_role
- field.field.cloud_config.aws_cloud.field_x_509_certificate
module:
- cloud
- options
- user
enforced:
module:
- aws_cloud
id: cloud_config.aws_cloud.default
targetEntityType: cloud_config
bundle: aws_cloud
......
......@@ -26,8 +26,12 @@ dependencies:
- field.field.cloud_server_template.aws_cloud.field_tags
- field.field.cloud_server_template.aws_cloud.field_version
module:
- cloud
- options
- user
enforced:
module:
- aws_cloud
id: cloud_server_template.aws_cloud.default
targetEntityType: cloud_server_template
bundle: aws_cloud
......
......@@ -3,6 +3,9 @@ status: true
dependencies:
module:
- cloud
enforced:
module:
- aws_cloud
id: cloud_config.field_access_key
field_name: field_access_key
entity_type: cloud_config
......
......@@ -3,6 +3,9 @@ status: true
dependencies:
module:
- cloud
enforced:
module:
- aws_cloud
id: cloud_config.field_account_id
field_name: field_account_id
entity_type: cloud_config
......
......@@ -4,6 +4,9 @@ dependencies:
module:
- cloud
- options
enforced:
module:
- aws_cloud
id: cloud_config.field_api_endpoint_uri
field_name: field_api_endpoint_uri
entity_type: cloud_config
......
......@@ -3,6 +3,9 @@ status: true
dependencies:
module:
- cloud
enforced:
module:
- aws_cloud
id: cloud_config.field_api_version
field_name: field_api_version
entity_type: cloud_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