Github user sanju1010 commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1011#discussion_r51857735
  
    --- Diff: test/integration/component/test_coreos.py ---
    @@ -0,0 +1,291 @@
    +# 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.
    +
    +""" P1 tests for coreos template and vm
    +"""
    +
    +from marvin.lib.base import (
    +    VirtualMachine,
    +    ServiceOffering,
    +    Account,
    +    SSHKeyPair,
    +    Host, Template)
    +from marvin.lib.common import (
    +    get_zone,
    +    get_template,
    +    list_routers)
    +from marvin.lib.utils import (
    +    cleanup_resources,
    +    get_hypervisor_type,
    +    get_process_status)
    +from marvin.cloudstackTestCase import cloudstackTestCase
    +# Import System modules
    +import tempfile
    +import time
    +import os
    +import base64
    +from nose.plugins.attrib import attr
    +from marvin.sshClient import SshClient
    +
    +
    +class TestDeployVmWithCoreosTemplate(cloudstackTestCase):
    +    """Tests for deploying VM  using coreos template
    +    """
    +
    +    @classmethod
    +    def setUpClass(cls):
    +        cls._cleanup = []
    +        cls.testClient = super(
    +            TestDeployVmWithCoreosTemplate,
    +            cls).getClsTestClient()
    +        cls.api_client = cls.testClient.getApiClient()
    +        cls.services = cls.testClient.getParsedTestDataConfig()
    +        cls.zone = get_zone(cls.api_client, 
cls.testClient.getZoneForTests())
    +        cls.service_offering = ServiceOffering.create(
    +            cls.api_client, 
services=cls.services["service_offerings"]["medium"])
    +        cls.account = Account.create(
    +            cls.api_client, services=cls.services["account"])
    +        cls.cleanup = [cls.account]
    +        cls.template = get_template(
    +            cls.api_client,
    +            cls.zone.id,
    +            cls.services["ostype"]
    +        )
    +        cls.services["coreos"][
    +            "hypervisor"] = cls.testClient.getHypervisorInfo()
    +        cls.userdata = '#cloud-config\n\ncoreos:\n  units:\n    - name: 
docker.service\n      command: start\n    ' \
    +                       '- name: web.service\n      command: start\n      
content: |\n        [Unit]\n        ' \
    +                       'After=docker.service\n        
Requires=docker.service\n        Description=Starts web server ' \
    +                       'container\n        [Service]\n        
TimeoutStartSec=0\n        ' \
    +                       'ExecStartPre=/usr/bin/docker pull httpd:2.4\n      
  ' \
    +                       'ExecStart=/usr/bin/docker run -d -p 8000:80 
httpd:2.4'
    +        cls.services["virtual_machine"]["userdata"] = cls.userdata
    +
    +        cls.keypair = SSHKeyPair.create(
    +            cls.api_client,
    +            name="coreos",
    +            account=cls.account.name,
    +            domainid=cls.account.domainid
    +        )
    +        cls.debug("Created a new keypair with name: %s" % cls.keypair.name)
    +
    +        cls.debug("Writing the private key to local file")
    +        cls.keyPairFilePath = tempfile.gettempdir() + os.sep + 
cls.keypair.name
    +        # Clenaup at end of execution
    +        cls.cleanup.append(cls.keyPairFilePath)
    +
    +        cls.debug("File path: %s" % cls.keyPairFilePath)
    +
    +        f = open(cls.keyPairFilePath, "w+")
    +        f.write(cls.keypair.privatekey)
    +        f.close()
    +        os.system("chmod 400 " + cls.keyPairFilePath)
    +        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__
    +        return
    +
    +    def setUp(self):
    +        self.api_client = self.testClient.getApiClient()
    +        return
    +
    +    def tearDown(self):
    +        # Clean up, terminate the created volumes
    +        cleanup_resources(self.api_client, self.cleanup)
    +        return
    +
    +    @classmethod
    +    def tearDownClass(cls):
    +        try:
    +            cleanup_resources(cls.api_client, cls._cleanup)
    +        except Exception as e:
    +            raise Exception("Warning: Exception during cleanup : %s" % e)
    +        return
    +
    +    @attr(tags=["advanced"], required_hardware="true")
    +    def test1_coreos_VM_creation(self):
    +
    +        self.hypervisor = str(get_hypervisor_type(self.api_client)).lower()
    +        self.services["virtual_machine"][
    +            "hypervisor"] = self.hypervisor.upper()
    +        if self.hypervisor == "vmware":
    +            self.services["coreos"][
    +                "url"] = self.services["coreos"]["urlvmware"]
    +            self.services["coreos"]["format"] = "OVA"
    +        elif self.hypervisor == "xenserver":
    +            self.services["coreos"][
    +                "url"] = self.services["coreos"]["urlxen"]
    +            self.services["coreos"]["format"] = "VHD"
    +        elif self.hypervisor == "kvm":
    +            self.services["coreos"][
    +                "url"] = self.services["coreos"]["urlkvm"]
    +            self.services["coreos"]["format"] = "QCOW2"
    +        elif self.hypervisor == "hyperv":
    +            self.services["coreos"][
    +                "url"] = self.services["coreos"]["urlxen"]
    +            self.services["coreos"]["format"] = "VHD"
    +
    +        template_created = Template.register(
    +            self.api_client,
    +            self.services["coreos"],
    +            self.zone.id,
    +            account=self.account.name,
    +            domainid=self.account.domainid)
    +        self.assertIsNotNone(template_created, "Template creation failed")
    +        # Wait for template to download
    +        template_created.download(self.api_client)
    +        self.cleanup.append(template_created)
    +        # Wait for template status to be changed across
    +        time.sleep(self.services["sleep"])
    +
    +        self.debug("Deploying instance in the account: %s" % 
self.account.name)
    +
    +        virtual_machine = VirtualMachine.create(
    +            self.api_client,
    +            self.services["virtual_machine"],
    +            templateid=template_created.id,
    +            accountid=self.account.name,
    +            domainid=self.account.domainid,
    +            zoneid=self.zone.id,
    +            serviceofferingid=self.service_offering.id,
    +            keypair=self.keypair.name,
    +            hypervisor=self.hypervisor,
    +            mode=self.zone.networktype,
    +            method="POST"
    +
    +        )
    +
    +        self.debug("Check if the VM is properly deployed or not?")
    +        vms = VirtualMachine.list(
    +            self.api_client,
    +            id=virtual_machine.id,
    +            listall=True
    +        )
    +        self.assertEqual(
    +            isinstance(vms, list),
    +            True,
    +            "List VMs should return the valid list"
    +        )
    +        vm = vms[0]
    +        self.assertEqual(
    +            vm.state,
    +            "Running",
    +            "VM state should be running after deployment"
    +        )
    +        virtual_machine.stop(self.api_client)
    +        virtual_machine.update(
    +            self.api_client,
    +            userdata=base64.b64encode(
    +                self.userdata))
    +        virtual_machine.start(self.api_client)
    +        self.assertEqual(
    +            vm.state,
    +            "Running",
    +            "VM state should be running"
    +        )
    +        # Wait for docker service to start
    +        time.sleep(300)
    +
    +        # Should be able to SSH VM
    +        try:
    +
    +            self.debug("SSH into VM: %s" % virtual_machine.ssh_ip)
    +            cmd = "docker ps"
    +            ssh = SshClient(virtual_machine.ssh_ip, 22, "core",
    +                            "", keyPairFiles=self.keyPairFilePath)
    +            result = ssh.execute(cmd)
    +
    +        except Exception as e:
    +            self.fail(
    +                "SSH Access failed for %s: %s" %
    +                (virtual_machine.ssh_ip, e)
    +            )
    +
    +        res = str(result)
    +        self.assertEqual(
    +            res.__contains__("httpd"),
    +            True,
    +            "docker web service not started in coreos vm ")
    +
    +        if self.zone.networktype == "Basic":
    +            list_router_response = list_routers(
    +                self.api_client,
    +                listall="true"
    +            )
    +        else:
    +            list_router_response = list_routers(
    +                self.api_Client,
    --- End diff --
    
    Replace self.api_Client with self.api_client


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to