VOL-1312 - Resource Manager should not require hard coded vendor/models

Changed extra-args parser to not require any validation checks from
a choice list.

Changed openolt to auto create the extra args from device info if
not provided via CLI.

Changed openolt to use model vs vendor as the resource manager
techprofile path.

Change-Id: Ib7befc581574abb5c4fb30355f830a9fdafe1b60
diff --git a/common/pon_resource_manager/resource_manager.py b/common/pon_resource_manager/resource_manager.py
index aa005de..f2c082d 100644
--- a/common/pon_resource_manager/resource_manager.py
+++ b/common/pon_resource_manager/resource_manager.py
@@ -46,8 +46,11 @@
     ALLOC_ID = 'ALLOC_ID'
     GEMPORT_ID = 'GEMPORT_ID'
 
-    # The resource ranges for a given device vendor_type should be placed
-    # at 'resource_manager/<technology>/resource_ranges/<olt_vendor_type>'
+    # Constants for passing command line arugments
+    OLT_MODEL_ARG = '--olt_model'
+
+    # The resource ranges for a given device model should be placed
+    # at 'resource_manager/<technology>/resource_ranges/<olt_model_type>'
     # path on the KV store.
     # If Resource Range parameters are to be read from the external KV store,
     # they are expected to be stored in the following format.
@@ -78,7 +81,7 @@
     NUM_OF_PON_PORT = "pon_ports"
 
     # PON Resource range configuration on the KV store.
-    # Format: 'resource_manager/<technology>/resource_ranges/<olt_vendor_type>'
+    # Format: 'resource_manager/<technology>/resource_ranges/<olt_model_type>'
     # The KV store backend is initialized with a path prefix and we need to
     # provide only the suffix.
     PON_RESOURCE_RANGE_CONFIG_PATH = 'resource_ranges/{}'
@@ -121,12 +124,12 @@
 
         try:
             self.technology = technology
-            self.extra_args = extra_args
+            self.extra_args = extra_args 
             self.device_id = device_id
             self.backend = backend
             self.host = host
             self.port = port
-            self.olt_vendor = None
+            self.olt_model = None
 
             self._kv_store = ResourceKvStore(technology, device_id, backend,
                                              host, port)
@@ -160,14 +163,14 @@
 
         :return boolean: True if PON resource ranges initialized else false
         """
-        self.olt_vendor = self._get_olt_vendor()
+        self.olt_model = self._get_olt_model()
         # Try to initialize the PON Resource Ranges from KV store based on the
-        # OLT vendor key, if available
-        if self.olt_vendor is None:
-            self._log.info("olt-vendor-unavailable--not-reading-from-kv-store")
+        # OLT model key, if available
+        if self.olt_model is None:
+            self._log.info("device-model-unavailable--not-reading-from-kv-store")
             return False
 
-        path = self.PON_RESOURCE_RANGE_CONFIG_PATH.format(self.olt_vendor)
+        path = self.PON_RESOURCE_RANGE_CONFIG_PATH.format(self.olt_model)
         try:
             # get resource from kv store
             result = self._kv_store.get_from_kv_store(path)
@@ -617,29 +620,27 @@
             path, json.dumps(gemport_ids)
         )
 
-    def _get_olt_vendor(self):
+    def _get_olt_model(self):
         """
-        Get olt vendor variant
+        Get olt model variant
 
-        :return: type of olt vendor
+        :return: type of olt model 
         """
-        olt_vendor = None
+        olt_model = None
         if self.extra_args and len(self.extra_args) > 0:
             parser = OltVendorArgumentParser(add_help=False)
-            parser.add_argument('--olt_vendor', '-o', action='store',
-                                choices=['default', 'asfvolt16', 'cigolt24',
-                                'tlabvolt4', 'tlabvolt8', 'tlabvolt16', 'tlabvolt24'],
-                                default='default')
+            parser.add_argument(PONResourceManager.OLT_MODEL_ARG, '-m', action='store', default='default')
             try:
                 args = parser.parse_args(shlex.split(self.extra_args))
                 self._log.debug('parsing-extra-arguments', args=args)
-                olt_vendor = args.olt_vendor
+                olt_model = args.olt_model
             except ArgumentError as e:
                 self._log.exception('invalid-arguments: {}', e=e)
             except Exception as e:
                 self._log.exception('option-parsing-error: {}', e=e)
 
-        return olt_vendor
+        self._log.debug('olt-model', olt_model=olt_model)
+        return olt_model
 
     def _generate_next_id(self, resource):
         """
diff --git a/tests/utests/common/test_pon_resource_manager.py b/tests/utests/common/test_pon_resource_manager.py
index 6205ee4..8a03294 100644
--- a/tests/utests/common/test_pon_resource_manager.py
+++ b/tests/utests/common/test_pon_resource_manager.py
@@ -42,7 +42,7 @@
 
     def test_init_pon_resource_ranges(self):
         output = json.dumps(self.default_resource_range).encode('utf-8')
-        self._rm._get_olt_vendor = Mock(return_value='default')
+        self._rm._get_olt_model = Mock(return_value='default')
         self._rm._kv_store.get_from_kv_store = Mock(return_value=output)
 
         self._rm.init_resource_ranges_from_kv_store()
diff --git a/voltha/adapters/openolt/README.md b/voltha/adapters/openolt/README.md
index 8f3d5e6..b2814ab 100644
--- a/voltha/adapters/openolt/README.md
+++ b/voltha/adapters/openolt/README.md
@@ -20,8 +20,8 @@
 The OpenOLT adapter interacts with Resource Manager module for PON resource assignments.

 The `openolt_resource_manager` module is responsible for interfacing with the Resource Manager.

 

-The Resource Manager optionally uses `olt_vendor_type` specific resource ranges to initialize the PON resource pools.

-In order to utilize this option, create an entry for `olt_vendor_type` specific PON resource ranges on the KV store.

+The Resource Manager optionally uses `olt_model_type` specific resource ranges to initialize the PON resource pools.

+In order to utilize this option, create an entry for `olt_model_type` specific PON resource ranges on the KV store.

 Please make sure to use the same KV store used by the VOLTHA core.

 

 ### For example

@@ -39,7 +39,7 @@
 ```

 This data should be put on the KV store location `resource_manager/xgspon/resource_ranges/asfvolt16`

 

-The format of the KV store location is `resource_manager/<technology>/resource_ranges/<olt_vendor_type>` 

+The format of the KV store location is `resource_manager/<technology>/resource_ranges/<olt_model_type>` 

 

 In the below example the KV store is assumed to be Consul. However the same is applicable to be etcd or any other KV store.

 Please make sure to use the same KV store used by the VOLTHA core.

@@ -47,8 +47,10 @@
 curl -X PUT -H "Content-Type: application/json" http://127.0.0.1:8500/v1/kv/resource_manager/xgspon/resource_ranges/asfvolt16 -d @./asfvolt16_resource_range.json 

 ```

 

-The `olt_vendor_type` should be referred to during the preprovisiong step as shown below. The `olt_vendor_type` is an extra option and

-should be specified after `--`. The `-o` specifies the `olt_vendor_type`. 

+The `olt_model_type` should be referred to during the preprovisiong step as shown below. The `olt_model_type` is an extra option and

+should be specified after `--`. The `--olt_model or -o` specifies the `olt_model_type`. The olt_model_type is also learned

+from the physical device when connecting and the value from the preprovisioning command is optional to override the model

+information learned from the device.

 

 ```bash

  (voltha) preprovision_olt -t openolt -H 192.168.50.100:9191 -- -o asfvolt16

@@ -58,7 +60,7 @@
 in `asfvolt16_resource_range.json` and placed on the KV store.

 

 #### Additional Notes

-If a `default` resource range profile should be used with all `olt_vendor_type`s, then place such Resource Range profile

+If a `default` resource range profile should be used with all `olt_model_type`s, then place such Resource Range profile

 at the below path on the KV store. 

 ```bash

 resource_manager/xgspon/resource_ranges/default

diff --git a/voltha/adapters/openolt/openolt_resource_manager.py b/voltha/adapters/openolt/openolt_resource_manager.py
index a59c7cd..6ac8a22 100644
--- a/voltha/adapters/openolt/openolt_resource_manager.py
+++ b/voltha/adapters/openolt/openolt_resource_manager.py
@@ -87,8 +87,9 @@
             technology = arange.technology
             self.log.info("device-info", technology=technology)
             ranges[technology] = arange
+            extra_args = self.extra_args + ' ' + PONResourceManager.OLT_MODEL_ARG +  ' {}'.format(self.device_info.model)
             resource_mgr = PONResourceManager(technology,
-                self.extra_args, self.device_id, self.args.backend, host, port)
+                extra_args, self.device_id, self.args.backend, host, port)
             resource_mgrs_by_tech[technology] = resource_mgr
             if global_resource_mgr is None: global_resource_mgr = resource_mgr
             for intf_id in arange.intf_ids: