karthick-rn commented on a change in pull request #395: URL: https://github.com/apache/fluo-muchos/pull/395#discussion_r648197985
########## File path: lib/muchos/config/azurevalidations.py ########## @@ -0,0 +1,253 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from .base import ConfigValidator +from .azurevalidationhelpers import ( + vmss_status_succeeded_if_exists, + vmss_cluster_has_appropriate_data_disk_count, + vmss_exists, +) +from azure.mgmt.compute import ComputeManagementClient +from azure.common.client_factory import get_client_from_cli_profile + + +def validate_azure_configs(config, action): + # get VM SKU resources for this location. we have to use + # a specific API version to do this as this resource_skus + # list operation is not allowed in any other API versions + # which are available with the version of Azure SDK + # that ships with Ansible for Azure + config.client = get_client_from_cli_profile( + ComputeManagementClient, api_version="2017-09-01" + ) + config.vm_skus_for_location = list( + filter( + lambda s: s.resource_type == "virtualMachines" + and config.location() in s.locations, + config.client.resource_skus.list(), + ) + ) + + # switch to 2018-06-01 API which has support for other operations + # including VMSS checks + config.client = get_client_from_cli_profile( + ComputeManagementClient, api_version="2018-06-01" + ) + + validations = ( + AZURE_VALIDATIONS["common"] + AZURE_VALIDATIONS[action] + if action in AZURE_VALIDATIONS + else [] + ) + return list( + filter( + lambda r: isinstance(r, str), + map(lambda v: v(config, config.client), validations), + ) + ) + + +AZURE_VALIDATIONS = { + "common": [ + # if VMSS instances are pending upgrade to latest version + # block the execution of the setup phase. + ConfigValidator( + vmss_status_succeeded_if_exists, + "VMSS must not exist or be in 'Succeeded' state", + ), + # Validate that the data disk configuration is appropriate + # considering temp disk usage etc. + ConfigValidator(vmss_cluster_has_appropriate_data_disk_count, None), + + ConfigValidator(lambda config, client: not config.use_multiple_vmss()), + # the VM SKU specified is not a valid Azure VM SKU + ConfigValidator( + lambda config, client: config.vm_sku() + in {s.name: s for s in config.vm_skus_for_location}, + "azure.vm_sku must be a valid VM SKU for the selected location", + ), + ConfigValidator( + lambda config, client: not config.use_multiple_vmss() + or all( + [ + vmss.get("sku") + in {s.name: s for s in config.vm_skus_for_location} + for vmss in config.azure_multiple_vmss_vars.get( + "vars_list", [] + ) + ] + ), + "when use_multiple_vmss == True, any VMSS with sku " + "must be a valid VM SKU for the selected location", + ), + # managed_disk_type in + # ['Standard_LRS', 'StandardSSD_LRS', Premium_LRS'] + ConfigValidator( + lambda config, client: config.managed_disk_type() + in ["Standard_LRS", "StandardSSD_LRS", "Premium_LRS"], + "managed_disk_type must be " + "one of Standard_LRS, StandardSSD_LRS, or Premium_LRS", + ), + ConfigValidator( + lambda config, client: not config.use_multiple_vmss() + or all( + [ + vmss.get("disk_sku") + in ["Standard_LRS", "StandardSSD_LRS", "Premium_LRS"] Review comment: I forgot about running `black`, thanks for pointing it. The reformatted code has been pushed via [e31ddc2](https://github.com/apache/fluo-muchos/pull/395/commits/e31ddc2e7d68683e05b4f0f87252b142375ce6d8) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
