Beispiel #1
0
    def _create_resource_group(cluster_details: dict) -> None:
        """Create the resource group if it does not exist.

        Args:
            cluster_details (dict): details of the cluster.

        Returns:
            None.
        """

        # Get params
        subscription = cluster_details["cloud"]["subscription"]
        resource_group = cluster_details["cloud"]["resource_group"]

        # Check if Azure CLI is installed, and print version
        azure_version = AzureController.get_version()
        logger.info_green(
            f"Your Azure CLI version: {azure_version['azure-cli']}")

        # Set subscription id
        AzureController.set_subscription(subscription=subscription)
        logger.info_green(f"Set subscription to '{subscription}'")

        # Check and create resource group
        resource_group_info = AzureController.get_resource_group(
            resource_group=resource_group)
        if resource_group_info:
            logger.warning_yellow(
                f"Azure resource group '{resource_group}' already exists")
        else:
            AzureController.create_resource_group(
                resource_group=resource_group,
                location=cluster_details["cloud"]["location"])
            logger.info_green(f"Resource group '{resource_group}' is created")
Beispiel #2
0
 def _create_virtual_machines(cls, test_config: dict):
     cls.build_arm_parameters(
         build_config={
             "location": cls.location,
             "default_username": cls.default_username,
             "default_public_key": test_config["cloud/default_public_key"],
             "ssh": {
                 "port": GlobalParams.DEFAULT_SSH_PORT
             },
             "api_server": {
                 "port": GrassParams.DEFAULT_API_SERVER_PORT
             }
         },
         export_path=cls.arm_parameters_file_export_path)
     AzureController.set_subscription(
         subscription=test_config["cloud/subscription"])
     AzureController.create_resource_group(
         resource_group=cls.resource_group, location=cls.location)
     AzureController.start_deployment(
         resource_group=cls.resource_group,
         deployment_name="cluster",
         template_file_path=cls.arm_template_file_path,
         parameters_file_path=cls.arm_parameters_file_export_path)
Beispiel #3
0
    def setUpClass(cls) -> None:
        # Get and set params
        GlobalParams.LOG_LEVEL = logging.DEBUG
        cls.test_id = uuid.uuid4().hex[:8]
        os.makedirs(
            os.path.expanduser(f"{GlobalPaths.MARO_TEST}/{cls.test_id}"),
            exist_ok=True)
        cls.test_file_path = os.path.abspath(__file__)
        cls.test_dir_path = os.path.dirname(cls.test_file_path)

        # Load config
        cls.config_path = os.path.normpath(
            os.path.join(cls.test_dir_path, "./config.yml"))

        # Load config
        with open(cls.config_path) as fr:
            config_details = yaml.safe_load(fr)
            if config_details["cloud/subscription"] and config_details[
                    "user/admin_public_key"]:
                pass
            else:
                raise Exception("Invalid config")

        # Create resource group
        AzureController.create_resource_group(cls.resource_group, cls.location)

        # Create ARM params
        template_file_location = f"{cls.test_dir_path}/test_checkpoint_template.json"
        base_parameters_file_location = f"{cls.test_dir_path}/test_checkpoint_parameters.json"
        parameters_file_location = os.path.expanduser(
            f"{GlobalPaths.MARO_TEST}/{cls.test_id}/test_checkpoint_parameters.json"
        )
        with open(base_parameters_file_location, "r") as f:
            base_parameters = json.load(f)
        with open(parameters_file_location, "w") as fw:
            parameters = base_parameters["parameters"]
            parameters["location"]["value"] = cls.location
            parameters["networkInterfaceName"]["value"] = f"{cls.test_id}-nic"
            parameters["networkSecurityGroupName"][
                "value"] = f"{cls.test_id}-nsg"
            parameters["virtualNetworkName"]["value"] = f"{cls.test_id}-vnet"
            parameters["publicIpAddressName"]["value"] = f"{cls.test_id}-pip"
            parameters["virtualMachineName"]["value"] = f"{cls.test_id}-vm"
            parameters["virtualMachineSize"]["value"] = "Standard_B2s"
            parameters["adminUsername"]["value"] = cls.admin_username
            parameters["adminPublicKey"]["value"] = config_details[
                "user/admin_public_key"]
            parameters["storageAccountName"]["value"] = f"{cls.test_id}st"
            json.dump(base_parameters, fw, indent=4)

        # Start ARM deployment
        AzureController.start_deployment(
            resource_group=cls.resource_group,
            deployment_name=cls.test_id,
            template_file=template_file_location,
            parameters_file=parameters_file_location)
        cls._gracefully_wait(15)

        # Get params after ARM deployment
        cls.conn_str = AzureController.get_connection_string(
            storage_account_name=f"{cls.test_id}st")
        ip_addresses = AzureController.list_ip_addresses(
            resource_group=cls.resource_group, vm_name=f"{cls.test_id}-vm")
        cls.ip_address = ip_addresses[0]["virtualMachine"]["network"][
            "publicIpAddresses"][0]["ipAddress"]