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

    https://github.com/apache/cloudstack/pull/1500#discussion_r60225742
  
    --- Diff: test/integration/component/test_volumes.py ---
    @@ -603,7 +603,134 @@ def test_01_volume_attach_detach(self):
                     "Check the state of VM"
                 )
             except Exception as e:
    -            self.fail("Exception occuered: %s" % e)
    +            self.fail("Exception occurred: %s" % e)
    +        return
    +    
    +    @attr(tags=["advanced", "advancedns"])
    +    def test_02_root_volume_attach_detach(self):
    +        """Test Root Volume attach/detach to VM
    +        """
    +
    +        # Validate the following
    +        # 1. Deploy a VM
    +        # 2. Check for root volume
    +        # 3. Stop VM
    +        # 4. Detach root volume
    +        # 5. Verify root volume detached
    +        # 6. Attach root volume
    +        # 7. Start VM
    +        
    +        try:
    +            # Check for root volume
    +            root_volume_response = Volume.list(
    +                self.apiclient,
    +                virtualmachineid=self.virtual_machine.id,
    +                type='ROOT',
    +                listall=True
    +            )
    +            self.assertNotEqual(
    +                root_volume_response,
    +                None,
    +                "Check if root volume exists in ListVolumes"
    +            )
    +            self.assertEqual(
    +                isinstance(root_volume_response, list),
    +                True,
    +                "Check list volumes response for valid list"
    +            )
    +            # Grab the root volume for later use
    +            root_volume = root_volume_response[0]
    +            
    +            # Stop VM
    +            self.debug("Stopping the VM: %s" % self.virtual_machine.id)
    +            self.virtual_machine.stop(self.apiclient)
    +            
    +            # Ensure VM is stopped before detaching the root volume
    +            time.sleep(self.services["sleep"])
    +
    +            vm_response = VirtualMachine.list(
    +                self.apiclient,
    +                id=self.virtual_machine.id,
    +            )
    +            vm = vm_response[0]
    +            self.assertEqual(
    +                vm.state,
    +                'Stopped',
    +                "Check the state of VM"
    +            )
    +            
    +            # Detach root volume from VM
    +            self.virtual_machine.detach_volume(
    +                self.apiclient,
    +                root_volume
    +            )
    +            
    +            # Verify that root disk is gone
    +            no_root_volume_response = Volume.list(
    +                self.apiclient,
    +                virtualmachineid=self.virtual_machine.id,
    +                type='ROOT',
    +                listall=True
    +            )
    +            self.assertEqual(
    +                no_root_volume_response,
    +                None,
    +                "Check if root volume exists in ListVolumes"
    +            )
    +            
    +            # Attach root volume to VM
    +            self.virtual_machine.attach_volume(
    +                self.apiclient,
    +                root_volume,
    +                0
    +            )
    +            
    +            # Check for root volume
    +            new_root_volume_response = Volume.list(
    +                self.apiclient,
    +                virtualmachineid=self.virtual_machine.id,
    +                type='ROOT',
    +                listall=True
    +            )
    +            self.assertNotEqual(
    +                new_root_volume_response,
    +                None,
    +                "Check if root volume exists in ListVolumes"
    +            )
    +            self.assertEqual(
    +                isinstance(new_root_volume_response, list),
    +                True,
    +                "Check list volumes response for valid list"
    +            )
    +            
    +            # Start VM
    +            self.virtual_machine.start(self.apiclient)
    +            # Sleep to ensure that VM is in ready state
    +            time.sleep(self.services["sleep"])
    +
    +            vm_response = VirtualMachine.list(
    +                self.apiclient,
    +                id=self.virtual_machine.id,
    +            )
    +            # Verify VM response to check whether VM deployment was 
successful
    +            self.assertEqual(
    +                isinstance(vm_response, list),
    +                True,
    +                "Check list VM response for valid list"
    +            )
    +            self.assertNotEqual(
    +                len(vm_response),
    +                0,
    +                "Check VMs available in List VMs response"
    +            )
    --- End diff --
    
    The more I look at this, I think I understand why you need 2 different 
tests.  The first test ensures that returned object is a list, however that 
only verifies the type and not the content of the list.  The second test 
ensures that the returned list isn't empty.  I guess it is conceivable that the 
VirtualMachine.list could return an empty (0 len) list, which would indeed by a 
problem.  I would need to look deeper into the cloudstackAPI code to verify 
VirtualMachine.list behavior, but that is the only logical reason I can think 
of for both tests.  I think it is best to leave this second test in here for 
now, as I think protects us from an empty list being returned and causing the 
assert vm.state= "Running" to fail.
    
    Thoughts?


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