Repository: openvstorage/framework

Issue:
No relation between vmachine and vdisk after creating virtual machine on KVM (virt-install)
After creating a virtual machine with KVM (virt-install) there is no relation between vmachine and vdisk. 

```
openvstorage:
  Installed: 2.7.0-rev.3556.7283113-1
```

```
2016-06-09 15:17:49 48300 +0200 - cmp04 - 24265/140712111441728 - celery/celery.pool - 15328 - DEBUG - TaskPool: Apply <function _fast_trace_task at 0x7ffa12f82cf8> (args:('ovs.machine.update_from_voldrv', 'ca920dbb-c200-41b2-8d21-06e77fe4bc01', [], {'storagedriver_id': u'myvpoolDCA2L4E3TFL83Br4', 'name': u'/DCA2L4E3TFL83Br4/VM_2515.xml'}, {'utc': True, u'is_eager': False, 'chord': None, u'group': None, 'args': [], 'retries': 0, u'delivery_info': {u'priority': None, u'redelivered': False, u'routing_key': u'sr.DCA2L4E3TFL83Br4', u'exchange': u'generic'}, 'expires': None, u'hostname': 'celery@cmp04', 'task': 'ovs.machine.update_from_voldrv', 'callbacks': None, u'correlation_id': u'ca920dbb-c200-41b2-8d21-06e77fe4bc01', 'errbacks': None, 'timelimit': (None, None), 'taskset': None, 'kwargs': {'storagedriver_id': u'myvpoolDCA2L4E3TFL83Br4', 'name': u'/DCA2L4E3TFL83Br4/VM_2515.xml'}, 'eta': '2016-06-09T13:17:49.472955+00:00', u'reply_to': u'e1edd6d9-73c0-314f-af60-39a76547cacc', 'id': 'ca920dbb-c200-41b2-8d21-06e77fe4bc01', u'headers': {}}) kwargs:{})
2016-06-09 15:17:49 76500 +0200 - cmp04 - 20485/140712111441728 - celery/celery.redirected - 15315 - WARNING - 2016-06-09 15:17:49 76400 +0200 - cmp04 - 20485/140712111441728 - log/volumedriver_task - 15314 - INFO - [ovs.lib.vmachine.update_from_voldrv] - [] - {"storagedriver_id": "myvpoolDCA2L4E3TFL83Br4", "name": "/DCA2L4E3TFL83Br4/VM_2515.xml"} - {"storagedriver": "b5ebe200-4734-407a-9742-f914d0580032"}
2016-06-09 15:17:52 17300 +0200 - cmp04 - 20485/140712111441728 - celery/celery.redirected - 15321 - WARNING - 2016-06-09 15:17:52 17300 +0200 - cmp04 - 20485/140712111441728 - extensions/volatile mutex - 15320 - WARNING - A lock on ovs_lock_DCA2L4E3TFL83Br4/VM_2515.xml_none was kept for 0.300060033798 sec
2016-06-09 15:17:52 44000 +0200 - cmp04 - 20485/140712111441728 - lib/vmachine - 15324 - INFO - Syncing vMachine (device DCA2L4E3TFL83Br4/VM_2515.xml, ip 192.168.122.1, mountpoint /mnt/myvpool)
2016-06-09 15:17:54 46400 +0200 - cmp04 - 20485/140712111441728 - lib/vmachine - 15335 - INFO **- Updating vMachine finished (name VM_2515, 0 vdisks (re)linked)**
2016-06-09 15:17:54 46500 +0200 - cmp04 - 20485/140712111441728 - celery/celery.redirected - 15337 - WARNING - 2016-06-09 15:17:54 46500 +0200 - cmp04 - 20485/140712111441728 - extensions/volatile mutex - 15336 - WARNING - A lock on ovs_lock_DCA2L4E3TFL83Br4/VM_2515.xml_none was kept for 2.29092502594 sec
```

**Workaround**
Change the code in /opt/OpenvStorage/ovs/lib/vmachine.py from: 
`datastores = dict([('{0}:{1}'.format(storagedriver.storage_ip, storagedriver.mountpoint), storagedriver) for storagedriver in storagedrivers])`
To: 
`datastores = dict([('127.0.0.1:{0}'.format(storagedriver.mountpoint), storagedriver) for storagedriver in storagedrivers])`



Discussion:
I believe this might be related to code @khenderick is tackling atm. It should use the storage IP not 127.0.0.1


Resolving patch:
diff --git a/ovs/lib/storagerouter.py b/ovs/lib/storagerouter.py
--- a/ovs/lib/storagerouter.py
+++ b/ovs/lib/storagerouter.py
@@ -86,6 +86,13 @@ class StorageRouterController(object):
     @staticmethod
     @celery.task(name='ovs.storagerouter.ping')
     def ping(storagerouter_guid, timestamp):
+        """
+        Ping storagerouter
+        :param storagerouter_guid: Storage Router guid to ping
+        :type storagerouter_guid: str
+        :param timestamp: timestamp
+        :type timestamp: int
+        """
         with volatile_mutex('storagerouter_heartbeat_{0}'.format(storagerouter_guid)):
             storagerouter = StorageRouter(storagerouter_guid)
             if timestamp > storagerouter.heartbeats.get('celery', 0):
@@ -191,7 +198,8 @@ def get_metadata(storagerouter_guid):
                 'shared_size': shared_size,
                 'readcache_size': readcache_size,
                 'writecache_size': writecache_size,
-                'scrub_available': StorageRouterController._check_scrub_partition_present()}
+                'scrub_available': StorageRouterController._check_scrub_partition_present(),
+                'hvtype': storagerouter.pmachine.hvtype}
 
     @staticmethod
     @celery.task(name='ovs.storagerouter.add_vpool')
@@ -522,6 +530,8 @@ def add_vpool(parameters):
         storage_ip = parameters['storage_ip']
         if vpool is not None:
             for existing_storagedriver in vpool.storagedrivers:
+                if existing_storagedriver.storagerouter.pmachine.hvtype == 'KVM':
+                    continue
                 if existing_storagedriver.storage_ip != storage_ip:
                     error_messages.append('Storage IP {0} is not identical to previously configured storage IPs'.format(storage_ip))
                     break
@@ -810,7 +820,7 @@ def add_vpool(parameters):
                 fragment_cache_info = ['alba', {'albamgr_cfg_url': 'etcd://127.0.0.1:2379{0}'.format(config_tree.format('abm_aa')),
                                                 'bucket_strategy': ['1-to-1', {'prefix': vpool.metadata[storagerouter.guid]['name'],
                                                                                'preset': vpool.metadata[storagerouter.guid]['preset']}],
-                                                'manifest_cache_size': 16*1024*1024*1024,
+                                                'manifest_cache_size': 16 * 1024 * 1024 * 1024,
                                                 'cache_on_read': fragment_cache_on_read,
                                                 'cache_on_write': fragment_cache_on_write}]
             else:
@@ -823,7 +833,7 @@ def add_vpool(parameters):
                 'log_level': 'info',
                 'port': alba_proxy.service.ports[0],
                 'ips': ['127.0.0.1'],
-                'manifest_cache_size': 16*1024*1024*1024,
+                'manifest_cache_size': 16 * 1024 * 1024 * 1024,
                 'fragment_cache': fragment_cache_info,
                 'albamgr_cfg_url': 'etcd://127.0.0.1:2379{0}'.format(config_tree.format('abm'))
             }), raw=True)
diff --git a/ovs/lib/vmachine.py b/ovs/lib/vmachine.py
--- a/ovs/lib/vmachine.py
+++ b/ovs/lib/vmachine.py
@@ -690,6 +690,8 @@ def update_vmachine_config(vmachine, vm_object, pmachine=None):
             # Updating and linking disks
             storagedrivers = StorageDriverList.get_storagedrivers()
             datastores = dict([('{0}:{1}'.format(storagedriver.storage_ip, storagedriver.mountpoint), storagedriver) for storagedriver in storagedrivers])
+            if vmachine.pmachine is not None and vmachine.pmachine.hvtype == 'KVM':
+                datastores.update(dict([('127.0.0.1:{0}'.format(storagedriver.mountpoint), storagedriver) for storagedriver in storagedrivers]))
             vdisk_guids = []
             mutex = volatile_mutex('{0}_{1}'.format(vmachine.name, vmachine.devicename))
             for disk in vm_object['disks']:


Test patch: