borisstoyanov commented on a change in pull request #3510: [WIP DO NOT MERGE] 
Allow additional config to vms
URL: https://github.com/apache/cloudstack/pull/3510#discussion_r351748609
 
 

 ##########
 File path: test/integration/smoke/test_deploy_vm_extra_config_data.py
 ##########
 @@ -0,0 +1,529 @@
+# 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.
+""" BVT tests for Virtual Machine additional configuration
+"""
+# Import System modules
+import urllib
+import xml.etree.ElementTree as ET
+
+from lxml import etree
+from marvin.cloudstackAPI import (updateVirtualMachine,
+                                  deployVirtualMachine,
+                                  destroyVirtualMachine,
+                                  stopVirtualMachine,
+                                  startVirtualMachine,
+                                  updateConfiguration)
+# Import Local Modules
+from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.lib.base import (Account,
+                             ServiceOffering,
+                             )
+from marvin.lib.common import (get_domain,
+                               get_zone,
+                               get_template,
+                               list_hosts)
+from marvin.lib.utils import *
+from nose.plugins.attrib import attr
+
+class TestAddConfigtoDeployVM(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        testClient = super(TestAddConfigtoDeployVM, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
+
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.apiclient)
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
+        cls.hypervisor = testClient.getHypervisorInfo()
+        cls.services['mode'] = cls.zone.networktype
+        cls.hostConfig = 
cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][
+            0].__dict__
+
+        # Set Zones and disk offerings
+        cls.services["small"]["zoneid"] = cls.zone.id
+
+        cls.services["iso1"]["zoneid"] = cls.zone.id
+
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        # Create an account, network, and IP addresses
+        cls.account = Account.create(
+            cls.apiclient,
+            cls.services["account"],
+            domainid=cls.domain.id
+        )
+        cls.service_offering = ServiceOffering.create(
+            cls.apiclient,
+            cls.services["service_offerings"]["small"]
+        )
+
+        cls.cleanup = [
+            cls.account,
+            cls.service_offering
+        ]
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            cls.apiclient = super(TestAddConfigtoDeployVM, 
cls).getClsTestClient().getApiClient()
+            # Clean up, terminate the created templates
+            cleanup_resources(cls.apiclient, cls.cleanup)
+
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.hypervisor = self.testClient.getHypervisorInfo()
+        self.dbclient = self.testClient.getDbConnection()
+
+        """
+        Set EnableAdditionalData to true
+        """
+        updateConfigurationCmd = updateConfiguration.updateConfigurationCmd()
+        updateConfigurationCmd.name = "enable.additional.vm.configuration"
+        updateConfigurationCmd.value = "true"
+        updateConfigurationCmd.scopename = "account"
+        updateConfigurationResponse = 
self.apiclient.updateConfiguration(updateConfigurationCmd)
+        self.debug("updated the parameter %s with value %s" % (
+            updateConfigurationResponse.name, 
updateConfigurationResponse.value))
+
+    # Ste Global Config value
+    def add_global_config(self, name, value):
+        self.apiclient = self.testClient.getApiClient()
+        self.hypervisor = self.testClient.getHypervisorInfo()
+        self.dbclient = self.testClient.getDbConnection()
+
+        cmd = updateConfiguration.updateConfigurationCmd()
+        cmd.name = name
+        cmd.value = value
+        return self.apiclient.updateConfiguration(cmd)
+
+    # Compare XML Element objects
+    def elements_equal(self, e1, e2):
+        if e1.tag != e2.tag:
+            return False
+        if e1.attrib != e2.attrib:
+            return False
+        if len(e1) != len(e2):
+            return False
+        return all(self.elements_equal(c1, c2) for c1, c2 in zip(e1, e2))
+
+    def destroy_vm(self, vm_id):
+        cmd = destroyVirtualMachine.destroyVirtualMachineCmd()
+        cmd.expunge = True
+        cmd.id = vm_id
+        return self.apiclient.destroyVirtualMachine(cmd)
+
+    def deploy_vm(self, hypervisor, extra_config=None):
+        cmd = deployVirtualMachine.deployVirtualMachineCmd()
+        if extra_config is not None:
+            cmd.extraconfig = extra_config
+
+        template = get_template(
+            self.apiclient,
+            self.zone.id,
+            hypervisor=hypervisor
+        )
+        cmd.zoneid = self.zone.id
+        cmd.templateid = template.id
+        cmd.serviceofferingid = self.service_offering.id
+        return self.apiclient.deployVirtualMachine(cmd)
+
+    def update_vm(self, id, extra_config):
+        cmd = updateVirtualMachine.updateVirtualMachineCmd()
+        cmd.id = id
+        cmd.extraconfig = extra_config
+        return self.apiclient.updateVirtualMachine(cmd)
+
+    def stop_vm(self, id):
+        cmd = stopVirtualMachine.stopVirtualMachineCmd()
+        cmd.id = id
+        return self.apiclient.stopVirtualMachine(cmd)
+
+    def start_vm(self, id):
+        cmd = startVirtualMachine.startVirtualMachineCmd()
+        cmd.id = id
+        return self.apiclient.startVirtualMachine(cmd)
+
+    # Parse extraconfig for config with that returned by xe vm-param-get ...
+    def get_xen_param_values(self, config):
+        equal_sign_index = config.index("=")
+        cmd_option = config[:equal_sign_index]
+        cmd_value = config[equal_sign_index + 1:]
+        return cmd_option, cmd_value
+
+    # Format vm config such that it equals the one from vmx file
+    def prepare_vmware_config(self, config):
+        equal_sign_index = config.index("=")
+        cmd_option = config[:equal_sign_index]
+        cmd_value = config[equal_sign_index + 1:]
+        return cmd_option + ' = '  '"{}"'.format(cmd_value)
+
+    # Get vm uuid from xenserver host
+    def get_vm_uuid(self, instance_name, ssh_client):
+        cmd = 'xe vm-list name-label={} params=uuid '.format(instance_name)
+        result = ssh_client.execute(cmd)
+        uuid_str = result[0]
+        i = uuid_str.index(":")
+        return uuid_str[i + 1:].strip()
+
+    @attr(tags=["devcloud", "advanced", "advancedns", "smoke", "basic", "sg"], 
required_hardware="true")
+    def test_01_deploy_vm_with_extraconfig_throws_exception_kvm(self):
+        '''
+        Test that extra config is not added when element tag is not added on 
the allowed list global config on KVM hosts
+        '''
+
+        hypervisor = self.hypervisor.lower()
+        if hypervisor != 'kvm':
+            raise self.skipTest("Skipping test case for non-kvm hypervisor")
+
+        '''
+        The following extraconfig is required for enabling hugepages on kvm
+        <memoryBacking>
+            <hugepages/>
+        </memoryBacking>
+        url encoded extra_config = 
'%3CmemoryBacking%3E%0D%0A++%3Chugepages%2F%3E%0D%0A%3C%2FmemoryBacking%3E'
+        '''
+        extraconfig = 
"%3CmemoryBacking%3E%0D%0A++%3Chugepages%2F%3E%0D%0A%3C%2FmemoryBacking%3E"
+
+        try:
+            # Clear KVM allow list to show that code throws exception when 
command is not included in the list
+            name = 'allow.additional.vm.configuration.list.kvm'
+
+            self.add_global_config(name, "")
+            self.assertRaises(Exception,
+                              self.deploy_vm(hypervisor, extraconfig),
 
 Review comment:
   ![Screenshot 2019-11-28 at 14 13 
53](https://user-images.githubusercontent.com/13551960/69805459-59ced200-11e9-11ea-8cab-9aec5008a65c.png)
   VMs per each hypervisor are being left behind, perhaps we could add a 
'self.destroy_vm(response.id)' same as next tests

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


With regards,
Apache Git Services

Reply via email to