weizhouapache commented on code in PR #6571:
URL: https://github.com/apache/cloudstack/pull/6571#discussion_r1042041197


##########
test/integration/smoke/test_vm_autoscaling.py:
##########
@@ -0,0 +1,1103 @@
+# 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.
+
+"""
+Tests of VM Autoscaling
+"""
+
+import logging
+import time
+import datetime
+
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.cloudstackAPI import stopVirtualMachine
+
+from marvin.lib.base import (Account,
+                             Autoscale,
+                             AutoScaleCondition,
+                             AutoScalePolicy,
+                             AutoScaleVmProfile,
+                             AutoScaleVmGroup,
+                             Configurations,
+                             DiskOffering,
+                             Domain,
+                             Project,
+                             ServiceOffering,
+                             VirtualMachine,
+                             Volume,
+                             Zone,
+                             Network,
+                             NetworkOffering,
+                             PublicIPAddress,
+                             LoadBalancerRule,
+                             VPC,
+                             VpcOffering,
+                             SSHKeyPair)
+
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template)
+from marvin.lib.utils import wait_until
+
+MIN_MEMBER = 1
+MAX_MEMBER = 2
+DEFAULT_EXPUNGE_VM_GRACE_PERIOD = 60
+DEFAULT_DURATION = 120
+DEFAULT_INTERVAL = 30
+DEFAULT_QUIETTIME = 60
+NAME_PREFIX = "AS-VmGroup-"
+
+CONFIG_NAME_DISK_CONTROLLER = "vmware.root.disk.controller"
+OS_DEFAULT = "osdefault"
+
+class TestVmAutoScaling(cloudstackTestCase):
+    """
+    Test VM autoscaling
+    """
+    @classmethod
+    def setUpClass(cls):
+        cls.testClient = super(
+            TestVmAutoScaling,
+            cls).getClsTestClient()
+        cls.apiclient = cls.testClient.getApiClient()
+        cls.services = cls.testClient.getParsedTestDataConfig()
+
+        cls.initial_vmware_root_disk_controller = Configurations.list(
+            cls.apiclient,
+            name=CONFIG_NAME_DISK_CONTROLLER)[0].value
+        Configurations.update(cls.apiclient,
+                              CONFIG_NAME_DISK_CONTROLLER,
+                              OS_DEFAULT)
+
+        cls.hypervisor = cls.testClient.getHypervisorInfo()
+        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
+        cls.zone = Zone(zone.__dict__)
+        cls.template = get_template(cls.apiclient, cls.zone.id)
+        cls.templatesize = int(cls.template.size / (1024 ** 3))
+        cls._cleanup = []
+
+        cls.logger = logging.getLogger("TestVmAutoScaling")
+        cls.stream_handler = logging.StreamHandler()
+        cls.logger.setLevel(logging.DEBUG)
+        cls.logger.addHandler(cls.stream_handler)
+
+        cls.domain = get_domain(cls.apiclient)
+
+        # 1. Create small service offering
+        cls.service_offering = ServiceOffering.create(
+            cls.apiclient,
+            cls.services["service_offerings"]["small"]
+        )
+        cls._cleanup.append(cls.service_offering)
+
+        cls.service_offering_new = ServiceOffering.create(
+            cls.apiclient,
+            cls.services["service_offerings"]["small"]
+        )
+        cls._cleanup.append(cls.service_offering_new)
+
+        # 2. Create disk offerings (fixed and custom)
+        cls.disk_offering_override = DiskOffering.create(
+            cls.apiclient,
+            cls.services["disk_offering"],
+            disksize=cls.templatesize + 1
+        )
+        cls._cleanup.append(cls.disk_offering_override)
+
+        cls.disk_offering_custom = DiskOffering.create(
+            cls.apiclient,
+            cls.services["disk_offering"],
+            custom=True
+        )
+        cls._cleanup.append(cls.disk_offering_custom)
+
+        cls.disk_offering_custom_new = DiskOffering.create(
+            cls.apiclient,
+            cls.services["disk_offering"],
+            custom=True
+        )
+        cls._cleanup.append(cls.disk_offering_custom_new)
+
+        # 3. Create network offering for isolated networks
+        cls.services["isolated_network_offering"]["serviceCapabilityList"] = {
+            "Lb": {
+                "SupportedLbIsolation": 'dedicated',
+                "VmAutoScaling": 'true'
+            },
+        }
+        cls.network_offering_isolated = NetworkOffering.create(
+            cls.apiclient,
+            cls.services["isolated_network_offering"]
+        )
+        cls.network_offering_isolated.update(cls.apiclient, state='Enabled')
+        cls._cleanup.append(cls.network_offering_isolated)
+
+        # 4. Create sub-domain
+        cls.sub_domain = Domain.create(
+            cls.apiclient,
+            cls.services["acl"]["domain1"]
+        )
+        cls._cleanup.append(cls.sub_domain)
+
+        # 5. Create regular user
+        cls.regular_user = Account.create(
+            cls.apiclient,
+            cls.services["acl"]["accountD11A"],
+            domainid=cls.sub_domain.id
+        )
+        cls._cleanup.append(cls.regular_user)
+
+        # 5. Create api clients for regular user
+        cls.regular_user_user = cls.regular_user.user[0]
+        cls.regular_user_apiclient = cls.testClient.getUserApiClient(
+            cls.regular_user_user.username, cls.sub_domain.name
+        )
+
+        # 7. Create networks for regular user
+        cls.services["network"]["name"] = "Test Network Isolated - Regular 
user - 1"
+        cls.user_network_1 = Network.create(
+            cls.regular_user_apiclient,
+            cls.services["network"],
+            networkofferingid=cls.network_offering_isolated.id,
+            zoneid=cls.zone.id
+        )
+
+        cls.services["network"]["name"] = "Test Network Isolated - Regular 
user - 2"
+        cls.user_network_2 = Network.create(
+            cls.regular_user_apiclient,
+            cls.services["network"],
+            networkofferingid=cls.network_offering_isolated.id,
+            zoneid=cls.zone.id
+        )
+
+        # 8. Create SSH Keypairs
+        cls.keypair_1 = SSHKeyPair.create(
+            cls.regular_user_apiclient,
+            name="keypair1"
+        )
+        cls.keypair_2 = SSHKeyPair.create(
+            cls.regular_user_apiclient,
+            name="keypair2"
+        )
+
+        # 9. Get counters for cpu and memory
+        counters = Autoscale.listCounters(
+            cls.regular_user_apiclient,
+            provider="VirtualRouter"
+        )
+        for counter in counters:
+            if counter.source == 'CPU':
+                cls.counter_cpu_id = counter.id
+            elif counter.source == 'MEMORY':
+                cls.counter_memory_id = counter.id
+            elif counter.source == 'VIRTUALROUTER' and counter.value == 
'public.network.received.average.mbps':
+                cls.counter_network_received_id = counter.id
+            elif counter.source == 'VIRTUALROUTER' and counter.value == 
'public.network.transmit.average.mbps':
+                cls.counter_network_transmit_id = counter.id
+            elif counter.source == 'VIRTUALROUTER' and counter.value == 
'virtual.network.lb.average.connections':
+                cls.counter_lb_connection_id = counter.id
+
+        if cls.hypervisor.lower() == 'vmware':
+            cls.counter_cpu_or_memory_id = cls.counter_memory_id
+        else:
+            cls.counter_cpu_or_memory_id = cls.counter_cpu_id
+
+        # 10. Create AS conditions
+        cls.scale_up_condition = AutoScaleCondition.create(
+            cls.regular_user_apiclient,
+            counterid = cls.counter_cpu_id,
+            relationaloperator = "GE",
+            threshold = 1
+        )
+
+        cls.scale_down_condition = AutoScaleCondition.create(
+            cls.regular_user_apiclient,
+            counterid = cls.counter_cpu_or_memory_id,
+            relationaloperator = "LE",
+            threshold = 100
+        )
+
+        cls._cleanup.append(cls.scale_up_condition)
+        cls._cleanup.append(cls.scale_down_condition)
+
+        # 11. Create AS policies
+        cls.scale_up_policy = AutoScalePolicy.create(
+            cls.regular_user_apiclient,
+            action='ScaleUp',
+            conditionids=','.join([cls.scale_up_condition.id]),
+            quiettime=DEFAULT_QUIETTIME,
+            duration=DEFAULT_DURATION
+        )
+
+        cls.scale_down_policy = AutoScalePolicy.create(
+            cls.regular_user_apiclient,
+            action='ScaleDown',
+            conditionids=cls.scale_down_condition.id,
+            quiettime=DEFAULT_QUIETTIME,
+            duration=DEFAULT_DURATION
+        )
+
+        cls._cleanup.append(cls.scale_up_policy)
+        cls._cleanup.append(cls.scale_down_policy)
+
+        # 12. Create AS VM Profile
+        cls.otherdeployparams = []
+        cls.addOtherDeployParam(cls.otherdeployparams, 
"overridediskofferingid", cls.disk_offering_override.id)
+        cls.addOtherDeployParam(cls.otherdeployparams, "diskofferingid", 
cls.disk_offering_custom.id)
+        cls.addOtherDeployParam(cls.otherdeployparams, "disksize", 3)
+        cls.addOtherDeployParam(cls.otherdeployparams, "keypairs", 
cls.keypair_1.name + "," + cls.keypair_2.name)
+        cls.addOtherDeployParam(cls.otherdeployparams, "networkids", 
cls.user_network_1.id + "," + cls.user_network_2.id)
+
+        cls.autoscaling_vmprofile = AutoScaleVmProfile.create(
+            cls.regular_user_apiclient,
+            serviceofferingid=cls.service_offering.id,
+            zoneid=cls.zone.id,
+            templateid=cls.template.id,
+            expungevmgraceperiod=DEFAULT_EXPUNGE_VM_GRACE_PERIOD,
+            otherdeployparams=cls.otherdeployparams
+        )
+
+        cls._cleanup.append(cls.autoscaling_vmprofile)
+
+        # 13. Acquire Public IP and create LoadBalancer rule
+        cls.public_ip_address = PublicIPAddress.create(
+            cls.regular_user_apiclient,
+            services=cls.services["network"],
+            networkid=cls.user_network_1.id
+        )
+
+        cls.services["lbrule"]["openfirewall"] = False
+        cls.load_balancer_rule = LoadBalancerRule.create(
+            cls.regular_user_apiclient,
+            cls.services["lbrule"],
+            ipaddressid=cls.public_ip_address.ipaddress.id,
+            networkid=cls.user_network_1.id
+        )
+
+        # 14. Create AS VM Group
+        cls.autoscaling_vmgroup = AutoScaleVmGroup.create(
+            cls.regular_user_apiclient,
+            name=NAME_PREFIX + format(datetime.datetime.now(), 
'%Y%m%d-%H%M%S'),
+            lbruleid=cls.load_balancer_rule.id,
+            minmembers=MIN_MEMBER,
+            maxmembers=MAX_MEMBER,
+            scaledownpolicyids=cls.scale_down_policy.id,
+            scaleuppolicyids=cls.scale_up_policy.id,
+            vmprofileid=cls.autoscaling_vmprofile.id,
+            interval=DEFAULT_INTERVAL
+        )

Review Comment:
   `autoscaling_vmgroup` is removed in the test
   I will add the other two to _cleanup. (they are removed in account removal)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to