Ejemplo n.º 1
0
 def test_attach_volume(self):
     """
         use external resource, try to attach but no disks
     """
     fake_ctx, fake_client = self._gen_volume_context_and_client()
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         volume.attach_volume(ctx=fake_ctx)
 def _attach_detach(self):
     def links_count():
         node_properties = self.relationctx.source.node.properties
         if node_properties['use_external_resource']:
             return [
                 len(d[1]) for d in self.vca_client.get_disks(
                     self.vcloud_config['vdc']
                 ) if d[0].name == node_properties['resource_id']
             ][0]
         else:
             return [
                 len(d[1]) for d in self.vca_client.get_disks(
                     self.vcloud_config['vdc']
                 ) if d[0].name == node_properties['volume']['name']
             ][0]
     with mock.patch('server_plugin.volume.ctx', self.relationctx):
         links_before = links_count()
         volume.attach_volume()
         self.assertEqual(links_before + 1, links_count())
         volume.detach_volume()
         self.assertEqual(links_before, links_count())
Ejemplo n.º 3
0
    def _attach_detach(self):
        def links_count():
            node_properties = self.relationctx.source.node.properties
            if node_properties['use_external_resource']:
                return [
                    len(d[1]) for d in self.vca_client.get_disks(
                        self.vcloud_config['vdc'])
                    if d[0].name == node_properties['resource_id']
                ][0]
            else:
                return [
                    len(d[1]) for d in self.vca_client.get_disks(
                        self.vcloud_config['vdc'])
                    if d[0].name == node_properties['volume']['name']
                ][0]

        with mock.patch('server_plugin.volume.ctx', self.relationctx):
            links_before = links_count()
            volume.attach_volume()
            self.assertEqual(links_before + 1, links_count())
            volume.detach_volume()
            self.assertEqual(links_before, links_count())