def vgpu_serviceoffering_creation(self,gtype,nvidiamodel):
              self.testdata["vgpu"]["service_offerings"][gtype]["serviceofferingdetails"] = [{'pciDevice': nvidiamodel},
                                                                                       {'vgpuType':gtype}]
              self.service_offering = ServiceOffering.create(
                                                       self.apiclient,
                                                       self.testdata["vgpu"]["service_offerings"][gtype]
                                                          )
              list_service_response = ServiceOffering.list(
               self.apiclient,
               id=self.service_offering.id
               )

              if list_service_response is None:
                 raise unittest.SkipTest("Check Service Offering list for %s service offering" %(gtype))

              self.assertEqual(
                 list_service_response[0].serviceofferingdetails.vgpuType,
                        gtype,
                    "Failed To Create Service Offering . Check vGPU Service Offering list for K2 passthrough"
                  )
              self.assertEqual(
                 list_service_response[0].displaytext,
                 self.testdata["vgpu"]["service_offerings"][gtype]["displaytext"],
                 "Check server displaytext in createServiceOfferings"
                )
              self.assertEqual(
               list_service_response[0].name,
               self.testdata["vgpu"]["service_offerings"][gtype]["name"],
               "Check name in createServiceOffering"
                )
              return(self.service_offering)
    def vgpu_serviceoffering_creation(self, gtype, nvidiamodel):
        self.testdata["vgpu"]["service_offerings"][gtype][
            "serviceofferingdetails"] = [{
                'pciDevice': nvidiamodel
            }, {
                'vgpuType': gtype
            }]
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.testdata["vgpu"]["service_offerings"][gtype])
        list_service_response = ServiceOffering.list(
            self.apiclient, id=self.service_offering.id)

        if list_service_response is None:
            raise unittest.SkipTest(
                "Check Service Offering list for %s service offering" %
                (gtype))

        self.assertEqual(
            list_service_response[0].serviceofferingdetails.vgpuType, gtype,
            "Failed To Create Service Offering . Check vGPU Service Offering list for K2 passthrough"
        )
        self.assertEqual(
            list_service_response[0].displaytext,
            self.testdata["vgpu"]["service_offerings"][gtype]["displaytext"],
            "Check server displaytext in createServiceOfferings")
        self.assertEqual(
            list_service_response[0].name,
            self.testdata["vgpu"]["service_offerings"][gtype]["name"],
            "Check name in createServiceOffering")
        return (self.service_offering)
示例#3
0
    def test_01_positive_tests_vm_deploy_shared_nw(self):
        """ Positive tests for VMLC test path - Advanced Zone in Shared Network

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        """

        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient,
            name=self.service_offering_1.name,
            listall=True
        )
        self.assertEqual(validateList(listServiceOfferings)[0], PASS,
                         "List validation failed for service offerings list")

        self.assertEqual(listServiceOfferings[0].name,
                         self.service_offering_1.name,
                         "Names of created service offering\
                         and listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(
            self.userapiclient,
            templatefilter="self",
            name=self.template.name,
            listall=True,
            zone=self.zone.id)
        self.assertEqual(validateList(listTemplates)[0], PASS,
                         "List validation failed for templates list")

        self.assertEqual(listTemplates[0].name, self.template.name,
                         "Names of created template and listed template\
                         not matching")

        network = CreateNetwork(self, SHARED_NETWORK)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            networkids=[network.id, ],
            zoneid=self.zone.id
        )
        self.cleanup.append(self.virtual_machine)
        return
    def test_01_positive_tests_vm_deploy_shared_nw(self):
        """ Positive tests for VMLC test path - Advanced Zone in Shared Network

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        """

        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient, name=self.service_offering_1.name, listall=True)
        self.assertEqual(
            validateList(listServiceOfferings)[0], PASS,
            "List validation failed for service offerings list")

        self.assertEqual(
            listServiceOfferings[0].name, self.service_offering_1.name,
            "Names of created service offering\
                         and listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(self.userapiclient,
                                      templatefilter="self",
                                      name=self.template.name,
                                      listall=True,
                                      zone=self.zone.id)
        self.assertEqual(
            validateList(listTemplates)[0], PASS,
            "List validation failed for templates list")

        self.assertEqual(
            listTemplates[0].name, self.template.name,
            "Names of created template and listed template\
                         not matching")

        network = CreateNetwork(self, SHARED_NETWORK)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            networkids=[
                network.id,
            ],
            zoneid=self.zone.id)
        self.cleanup.append(self.virtual_machine)
        return
    def test_03_list_all_Serviceofferings_with_noparams(self):
        """
        Test List Service Offerings with No Parameters
        """

        serviceofferingvailable = 0
        listserviceofferings = ServiceOffering.list(self.user_api_client)

        self.assertEqual(
            isinstance(listserviceofferings, list), True,
            "Check list Service Offerings response returns a valid list")

        for serviceoffering1 in listserviceofferings:
            if serviceoffering1.name == "Small Instance":
                serviceofferingvailable = serviceofferingvailable + 1
            elif serviceoffering1.name == "Medium Instance":
                serviceofferingvailable = serviceofferingvailable + 1

        if serviceofferingvailable < 2:
            self.fail("All the default service offerings are not listed")
    def test_03_list_all_Serviceofferings_with_noparams(self):
        """
        Test List Service Offerings with No Parameters
        """

        serviceofferingvailable=0
        listserviceofferings=ServiceOffering.list(self.user_api_client)

        self.assertEqual(
                            isinstance(listserviceofferings, list),
                            True,
                            "Check list Service Offerings response returns a valid list"
                        )

        for serviceoffering1 in listserviceofferings:
            if serviceoffering1.name=="Small Instance":
                serviceofferingvailable=serviceofferingvailable+1
            elif serviceoffering1.name=="Medium Instance":
                serviceofferingvailable=serviceofferingvailable+1

        if serviceofferingvailable<2:
            self.fail("All the default service offerings are not listed")
示例#7
0
    def test_01_positive_tests_vm_operations_basic_zone(self):
        """ Positive tests for VMLC test path - Basic Zone

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        # 4.  Enable networking for reaching to VM thorugh SSH
        # 5.  Check VM accessibility through SSH
        # 6.  Stop vm and verify vm is not accessible
        # 7.  Start vm and verify vm is not accessible
        # 8.  Reboot vm and verify vm is not accessible
        # 9.  Destroy and recover VM
        # 10. Change service offering of VM to a different service offering
        # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to
        #     as specified in new service offering
            # 12. Start VM and verify VM accessibility
        # 13. Find suitable host for VM to migrate and migrate the VM
        # 14. Verify VM accessibility on new host
        """

        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient,
            name=self.service_offering_1.name,
            listall=True
        )
        self.assertEqual(validateList(listServiceOfferings)[0], PASS,
                         "List validation failed for service offerings list")
        self.assertEqual(listServiceOfferings[0].name,
                         self.service_offering_1.name,
                         "Names of created service offering and\
                         listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(self.userapiclient,
                                      templatefilter="self",
                                      name=self.template.name,
                                      listall=True,
                                      zone=self.zone.id
                                      )

        self.assertEqual(validateList(listTemplates)[0], PASS,
                         "List validation failed for\
                         templates list")

        self.assertEqual(listTemplates[0].name, self.template.name,
                         "Names of created template and listed template\
                         not matching")

        # Enable networking for reaching to VM thorugh SSH
        security_group = SecurityGroup.create(
            self.apiclient,
            self.testdata["security_group"],
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.cleanup.append(security_group)
        # Authorize Security group to SSH to VM
        security_group.authorize(
            self.apiclient,
            self.testdata["ingress_rule"],
            account=self.account.name,
            domainid=self.account.domainid
        )

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            zoneid=self.zone.id,
            securitygroupids=[security_group.id, ]
        )
        self.cleanup.append(self.virtual_machine)
        # Check VM accessibility
        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Stop VM and verify VM is not accessible
        self.virtual_machine.stop(self.userapiclient)

        with self.assertRaises(Exception):
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password,
                      retries=0
                      )

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Reboot VM and verify that it is accessible
        self.virtual_machine.reboot(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Destroy and recover VM
        self.virtual_machine.delete(self.userapiclient, expunge=False)
        self.virtual_machine.recover(self.apiclient)

        # Change service offering of VM and verify that it is changed
        self.virtual_machine.change_service_offering(
            self.userapiclient,
            serviceOfferingId=self.service_offering_2.id
        )

        VerifyChangeInServiceOffering(self,
                                      self.virtual_machine,
                                      self.service_offering_2)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        return
示例#8
0
    def test_01_positive_tests_vm_operations_advanced_zone(self, value):
        """ Positive tests for VMLC test path - Advanced Zone

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        # 4.  Enable networking for reaching to VM thorugh SSH
        # 5.  Check VM accessibility through SSH
        # 6.  Stop vm and verify vm is not accessible
        # 7.  Start vm and verify vm is not accessible
        # 8.  Reboot vm and verify vm is not accessible
        # 9.  Destroy and recover VM
        # 10. Change service offering of VM to a different service offering
        # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to
        #     as specified in new service offering
        # 12. Start VM and verify VM accessibility
        # 13. Find suitable host for VM to migrate and migrate the VM
        # 14. Verify VM accessibility on new host
        """
        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient,
            name=self.service_offering_1.name,
            listall=True
        )
        self.assertEqual(validateList(listServiceOfferings)[0], PASS,
                         "List validation failed for service offerings list")

        self.assertEqual(listServiceOfferings[0].name,
                         self.service_offering_1.name,
                         "Names of created service offering\
                         and listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(
            self.userapiclient,
            templatefilter="self",
            name=self.template.name,
            listall=True,
            zone=self.zone.id)
        self.assertEqual(validateList(listTemplates)[0], PASS,
                         "List validation failed for templates list")

        self.assertEqual(listTemplates[0].name, self.template.name,
                         "Names of created template and listed template\
                         not matching")

        network = CreateNetwork(self, value)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            networkids=[network.id, ],
            zoneid=self.zone.id
        )
        self.cleanup.append(self.virtual_machine)
        publicip = PublicIPAddress.create(
            self.userapiclient, accountid=self.account.name,
            zoneid=self.zone.id, domainid=self.account.domainid,
            networkid=network.id, vpcid=self.vpcid
        )

        if value == VPC_NETWORK:
            lb_rule = LoadBalancerRule.create(
                self.apiclient,
                self.testdata["vpclbrule"],
                ipaddressid=publicip.ipaddress.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkid=network.id,
                vpcid=self.vpcid
            )
            lb_rule.assign(self.apiclient, [self.virtual_machine])

            # Opening up the ports in VPC
            NetworkACL.create(
                self.apiclient,
                networkid=network.id,
                services=self.testdata["natrule"],
                traffictype='Ingress'
            )
        elif value == ISOLATED_NETWORK:
            FireWallRule.create(
                self.userapiclient,
                ipaddressid=publicip.ipaddress.id,
                protocol='TCP',
                cidrlist=[self.testdata["fwrule"]["cidr"]],
                startport=self.testdata["fwrule"]["startport"],
                endport=self.testdata["fwrule"]["endport"]
            )

            NATRule.create(
                self.userapiclient,
                self.virtual_machine,
                self.testdata["natrule"],
                ipaddressid=publicip.ipaddress.id,
                networkid=network.id
            )

        # Check VM accessibility
        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Stop VM and verify VM is not accessible
        self.virtual_machine.stop(self.userapiclient)

        with self.assertRaises(Exception):
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password,
                      retries=0)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Reboot VM and verify that it is accessible
        self.virtual_machine.reboot(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Destroy and recover VM
        self.virtual_machine.delete(self.apiclient, expunge=False)
        self.virtual_machine.recover(self.apiclient)

        # Change service offering of VM and verify that it is changed
        self.virtual_machine.change_service_offering(
            self.userapiclient,
            serviceOfferingId=self.service_offering_2.id
        )

        VerifyChangeInServiceOffering(self,
                                      self.virtual_machine,
                                      self.service_offering_2)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        return
    def test_01_positive_tests_vm_operations_basic_zone(self):
        """ Positive tests for VMLC test path - Basic Zone

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        # 4.  Enable networking for reaching to VM thorugh SSH
        # 5.  Check VM accessibility through SSH
        # 6.  Stop vm and verify vm is not accessible
        # 7.  Start vm and verify vm is not accessible
        # 8.  Reboot vm and verify vm is not accessible
        # 9.  Destroy and recover VM
        # 10. Change service offering of VM to a different service offering
        # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to
        #     as specified in new service offering
            # 12. Start VM and verify VM accessibility
        # 13. Find suitable host for VM to migrate and migrate the VM
        # 14. Verify VM accessibility on new host
        """

        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient, name=self.service_offering_1.name, listall=True)
        self.assertEqual(
            validateList(listServiceOfferings)[0], PASS,
            "List validation failed for service offerings list")
        self.assertEqual(
            listServiceOfferings[0].name, self.service_offering_1.name,
            "Names of created service offering and\
                         listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(self.userapiclient,
                                      templatefilter="self",
                                      name=self.template.name,
                                      listall=True,
                                      zone=self.zone.id)

        self.assertEqual(
            validateList(listTemplates)[0], PASS, "List validation failed for\
                         templates list")

        self.assertEqual(
            listTemplates[0].name, self.template.name,
            "Names of created template and listed template\
                         not matching")

        # Enable networking for reaching to VM thorugh SSH
        security_group = SecurityGroup.create(self.apiclient,
                                              self.testdata["security_group"],
                                              account=self.account.name,
                                              domainid=self.account.domainid)
        self.cleanup.append(security_group)
        # Authorize Security group to SSH to VM
        security_group.authorize(self.apiclient,
                                 self.testdata["ingress_rule"],
                                 account=self.account.name,
                                 domainid=self.account.domainid)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            zoneid=self.zone.id,
            securitygroupids=[
                security_group.id,
            ])
        self.cleanup.append(self.virtual_machine)
        # Check VM accessibility
        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Stop VM and verify VM is not accessible
        self.virtual_machine.stop(self.userapiclient)

        with self.assertRaises(Exception):
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password,
                      retries=0)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Reboot VM and verify that it is accessible
        self.virtual_machine.reboot(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Destroy and recover VM
        self.virtual_machine.delete(self.userapiclient, expunge=False)
        self.virtual_machine.recover(self.apiclient)

        # Change service offering of VM and verify that it is changed
        self.virtual_machine.change_service_offering(
            self.userapiclient, serviceOfferingId=self.service_offering_2.id)

        VerifyChangeInServiceOffering(self, self.virtual_machine,
                                      self.service_offering_2)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        return
示例#10
0
    def test_01_positive_tests_vm_operations_advanced_zone(self, value):
        """ Positive tests for VMLC test path - Advanced Zone

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        # 4.  Enable networking for reaching to VM thorugh SSH
        # 5.  Check VM accessibility through SSH
        # 6.  Stop vm and verify vm is not accessible
        # 7.  Start vm and verify vm is not accessible
        # 8.  Reboot vm and verify vm is not accessible
        # 9.  Destroy and recover VM
        # 10. Change service offering of VM to a different service offering
        # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to
        #     as specified in new service offering
        # 12. Start VM and verify VM accessibility
        # 13. Find suitable host for VM to migrate and migrate the VM
        # 14. Verify VM accessibility on new host
        """
        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient, name=self.service_offering_1.name, listall=True)
        self.assertEqual(
            validateList(listServiceOfferings)[0], PASS,
            "List validation failed for service offerings list")

        self.assertEqual(
            listServiceOfferings[0].name, self.service_offering_1.name,
            "Names of created service offering\
                         and listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(self.userapiclient,
                                      templatefilter="self",
                                      name=self.template.name,
                                      listall=True,
                                      zone=self.zone.id)
        self.assertEqual(
            validateList(listTemplates)[0], PASS,
            "List validation failed for templates list")

        self.assertEqual(
            listTemplates[0].name, self.template.name,
            "Names of created template and listed template\
                         not matching")

        network = CreateNetwork(self, value)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            networkids=[
                network.id,
            ],
            zoneid=self.zone.id)
        self.cleanup.append(self.virtual_machine)
        publicip = PublicIPAddress.create(self.userapiclient,
                                          accountid=self.account.name,
                                          zoneid=self.zone.id,
                                          domainid=self.account.domainid,
                                          networkid=network.id,
                                          vpcid=self.vpcid)

        if value == VPC_NETWORK:
            lb_rule = LoadBalancerRule.create(
                self.apiclient,
                self.testdata["vpclbrule"],
                ipaddressid=publicip.ipaddress.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkid=network.id,
                vpcid=self.vpcid)
            lb_rule.assign(self.apiclient, [self.virtual_machine])

            # Opening up the ports in VPC
            NetworkACL.create(self.apiclient,
                              networkid=network.id,
                              services=self.testdata["natrule"],
                              traffictype='Ingress')
        elif value == ISOLATED_NETWORK:
            FireWallRule.create(self.userapiclient,
                                ipaddressid=publicip.ipaddress.id,
                                protocol='TCP',
                                cidrlist=[self.testdata["fwrule"]["cidr"]],
                                startport=self.testdata["fwrule"]["startport"],
                                endport=self.testdata["fwrule"]["endport"])

            NATRule.create(self.userapiclient,
                           self.virtual_machine,
                           self.testdata["natrule"],
                           ipaddressid=publicip.ipaddress.id,
                           networkid=network.id)

        # Check VM accessibility
        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Stop VM and verify VM is not accessible
        self.virtual_machine.stop(self.userapiclient)

        with self.assertRaises(Exception):
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password,
                      retries=0)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Reboot VM and verify that it is accessible
        self.virtual_machine.reboot(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Destroy and recover VM
        self.virtual_machine.delete(self.apiclient, expunge=False)
        self.virtual_machine.recover(self.apiclient)

        # Change service offering of VM and verify that it is changed
        self.virtual_machine.change_service_offering(
            self.userapiclient, serviceOfferingId=self.service_offering_2.id)

        VerifyChangeInServiceOffering(self, self.virtual_machine,
                                      self.service_offering_2)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        return
 def test_03_network_off_CS5332(self):
     """
     @Desc: Test Network offering with Custom system offering for VR
     @Steps:
     Step1: Create new system offering for domain router
     Step2: Verify the custom system offering creation for domain router
     Step3: Create new network offering with domain router system offering created in step1
     Step4: Verify the network offering creation with custom system offering for VR
     Step5: Enable the network offering created in step3
     Step5: Create isolated guest network using network offering created in step3
     Step6: Deploy guest vm in network created above
     """
     #create custom system offering for VR
     self.services["service_offering"]["name"] = "test_service_offering_for_router"
     self.services["service_offering"]["displaytext"] = "test_service_offering_for_router"
     self.services["service_offering"]["cpuspeed"] = 500
     self.services["service_offering"]["memory"] = 512
     self.services["service_offering"]["systemvmtype"] = "domainrouter"
     self.services["service_offering"]["storagetype"] = "shared"
     self.services["service_offering"]["issystem"] = "true"
     vr_sys_off = ServiceOffering.create(
                                         self.apiclient,
                                         self.services["service_offering"],
                                         )
     self.assertIsNotNone(
                          vr_sys_off,
                          "Failed to create custom system offering for VR"
                          )
     vr_sys_off_res = ServiceOffering.list(
                                           self.apiclient,
                                           id = vr_sys_off.id,
                                           issystem = "true"
                                           )
     status = validateList(vr_sys_off_res)
     self.assertEquals(
         PASS,
         status[0],
         "Listing of VR system offering failed"
     )
     self.assertEqual(
                      len(vr_sys_off_res),
                      1,
                      "Listing more than VR system offerings created"
     )
     self.debug("Created system offering with id %s" % vr_sys_off.id)
     # Create a network offering with all virtual router services enabled using custom system offering for VR
     self.debug(
         "Creating n/w offering with all services in VR & using custom system offering for VR"
     )
     self.network_offering = NetworkOffering.create(
                                               self.apiclient,
                                               self.services["network_offering"],
                                               conservemode=False,
                                               serviceofferingid=vr_sys_off.id
                                               )
     self.assertIsNotNone(
                          self.network_offering,
                          "Failed to create network offering with custom system offering for VR"
                          )
     network_off_res = NetworkOffering.list(
                                            self.apiclient,
                                            id=self.network_offering.id
                                            )
     status = validateList(network_off_res)
     self.assertEquals(
                       PASS,
                       status[0],
                       "Listing of network offerings failed"
     )
     self.assertEquals(
                       len(network_off_res),
                       1,
                       "More than one network offerings are created"
     )
     self.assertEquals(
                       network_off_res[0].serviceofferingid,
                       vr_sys_off.id,
                       "FAIL: Network offering has been created with default system offering"
     )
     self.cleanup.append(self.network_offering)
     self.cleanup.append(vr_sys_off)
     self.debug("Created n/w offering with ID: %s" % self.network_offering.id)
     # Enable Network offering
     self.network_offering.update(self.apiclient, state='Enabled')
     # Creating network using the network offering created
     self.debug("Creating network with network offering: %s" % self.network_offering.id)
     self.network = Network.create(
                                   self.apiclient,
                                   self.services["network"],
                                   accountid=self.account.name,
                                   domainid=self.account.domainid,
                                   networkofferingid=self.network_offering.id,
                                   zoneid=self.zone.id
                                   )
     self.assertIsNotNone(self.network,"Failed to create network")
     self.debug("Created network with ID: %s" % self.network.id)
     self.debug("Deploying VM in account: %s" % self.account.name)
     # Spawn an instance in that network
     virtual_machine = VirtualMachine.create(
                                             self.apiclient,
                                             self.services["virtual_machine"],
                                             accountid=self.account.name,
                                             domainid=self.account.domainid,
                                             serviceofferingid=self.service_offering.id,
                                             networkids=[str(self.network.id)]
                                             )
     self.assertIsNotNone(
                          virtual_machine,
                          "VM creation failed with network %s" % self.network.id
                          )
     self.debug("Deployed VM in network: %s" % self.network.id)
     return