borisstoyanov commented on a change in pull request #3425: [WIP DO NOT MERGE] 
Better tracking host maintanence success and failure
URL: https://github.com/apache/cloudstack/pull/3425#discussion_r339486165
 
 

 ##########
 File path: test/integration/smoke/test_host_maintenance.py
 ##########
 @@ -254,25 +301,101 @@ def 
test_02_cancel_host_maintenace_with_migration_jobs(self):
                 self.logger.debug("Creating vms = {}".format(no_vm_req))
                 self.vmlist = self.createVMs(listHost[0].id, no_vm_req)
         
-        vm_migrating=False
+        migrations_finished = True
         
         try:
-           
-           vm_migrating = self.hostPrepareAndCancelMaintenance(listHost[0].id, 
listHost[1].id, self.checkVmMigratingOnHost)
-           
-           vm_migrating = self.hostPrepareAndCancelMaintenance(listHost[1].id, 
listHost[0].id, self.checkVmMigratingOnHost)
+            migrations_finished = 
self.hostPrepareAndCancelMaintenance(listHost[0].id, listHost[1].id)
+
+            if migrations_finished:
+                migrations_finished = 
self.hostPrepareAndCancelMaintenance(listHost[1].id, listHost[0].id)
            
         except Exception as e:
             self.logger.debug("Exception {}".format(e))
             self.fail("Cancel host maintenance failed {}".format(e[0]))
-        
 
-        if (vm_migrating == False):
-            raise unittest.SkipTest("No VM is migrating and the test will not 
be able to check the conditions the test is intended for");
-                
-            
+
+        if (migrations_finished == False):
+            raise unittest.SkipTest("VMs are still migrating and the test will 
not be able to check the conditions the test is intended for");
+
+        return
+
+    @attr(
+        tags=[
+            "advanced",
+            "advancedns",
+            "smoke",
+            "basic",
+            "eip",
+            "sg"],
+        required_hardware="true")
+    def test_03_cancel_host_maintenace_with_migration_jobs_ports_blocked(self):
+
+        listHost = Host.list(
+            self.apiclient,
+            type='Routing',
+            zoneid=self.zone.id,
+            podid=self.pod.id,
+        )
+        for host in listHost:
+            self.logger.debug('2 Hypervisor = {}'.format(host.id))
+
+        if (len(listHost) != 2):
+            raise unittest.SkipTest("Cancel host maintenance when VMs are 
migrating can only be tested with 2 hosts");
+            return
+
+        target_host_id = listHost[0].id
+        other_host_id = listHost[1].id
+
+        no_of_vms = self.noOfVMsOnHost(target_host_id)
+
+        # Need only 2 VMs for this case.
+        if no_of_vms < 2:
+            self.logger.debug("Create VMs as there are not enough vms to check 
host maintenance")
+            no_vm_req = 2 - no_of_vms
+            if (no_vm_req > 0):
+                self.logger.debug("Creating vms = {}".format(no_vm_req))
+                self.vmlist = self.createVMs(listHost[0].id, no_vm_req)
+
+        migrations_finished = True
+
+        ssh_client = self.get_ssh_client(listHost[1].ipaddress)
+        ssh_client.execute("iptables -I OUTPUT -j REJECT -m state --state NEW 
-m tcp -p tcp --dport 49152:49215 -m comment --comment 'test block migrations'")
+        ssh_client.execute("iptables -I OUTPUT -j REJECT -m state --state NEW 
-m tcp -p tcp --dport 16509 -m comment --comment 'test block migrations'")
+
+        cmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
+        cmd.id = target_host_id
+        self.logger.debug('Sending Host with id {} to 
prepareHostForMaintenance'.format(target_host_id))
+        response = self.apiclient.prepareHostForMaintenance(cmd)
+
+        self.logger.debug('Attempting to put host with id {} in 
Maintenance'.format(target_host_id))
+
+        error_in_maintenance_reached = 
self.wait_until_host_is_in_state(target_host_id, "ErrorInMaintenance")
+
+        self.logger.debug('Canceling Host with id {} from 
maintain'.format(target_host_id))
+        cmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
+        cmd.id = target_host_id
+        self.apiclient.cancelHostMaintenance(cmd)
+
+        self.logger.debug('Host with id {} has been sent to 
cancelHostMaintenance'.format(target_host_id))
+
+        ssh_client.execute("iptables -I OUTPUT -j ACCEPT -m state --state NEW 
-m tcp -p tcp --dport 49152:49215 -m comment --comment 'open port for 
migrations'")
+        ssh_client.execute("iptables -I OUTPUT -j ACCEPT -m state --state NEW 
-m tcp -p tcp --dport 16509 -m comment --comment 'open port for migrations'")
+
 
 Review comment:
   We're not making any assertions on results here, or I've missed it? Simply 
relying on executing api calls and not getting failures does not mean the 
operation is successful. We need to assert particular response attribute is for 
example "successful" and/or assert listing of VMs in and out of the host. 

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