Allow User to Specify Flavor 27/36327/2
authormbeierl <mark.beierl@dell.com>
Wed, 21 Jun 2017 20:02:57 +0000 (16:02 -0400)
committermbeierl <mark.beierl@dell.com>
Mon, 26 Jun 2017 17:00:01 +0000 (13:00 -0400)
Adds flavor as parameter to ReST /configurations API and passes
it through to the heat template creation.

Change-Id: Id3632fb571da9da51b4d75db58c7a7c0a91e0ccf
JIRA: STORPERF-92
Signed-off-by: mbeierl <mark.beierl@dell.com>
ci/start_job.sh
rest_server.py
storperf/resources/hot/agent-group.yaml
storperf/storperf_master.py
tests/db_tests/configuration_db_test.py
tests/storperf_master_test.py

index 0a149fd..487e0c6 100755 (executable)
@@ -15,7 +15,7 @@ cat << EOF > body.json
    "steady_state_samples": ${STEADY_STATE_SAMPLES},
    "queue_depths": "${QUEUE_DEPTH}",
    "workload": "${WORKLOAD}",
-    "metadata": {
+   "metadata": {
         "disk_type": "${DISK_TYPE}",
         "pod_name": "${POD_NAME}",
         "scenario_name": "${SCENARIO_NAME}",
index 67d71a5..5bff09c 100644 (file)
@@ -12,7 +12,7 @@ import logging.config
 import os
 import sys
 
-from flask import abort, Flask, request, jsonify, send_from_directory
+from flask import abort, Flask, request, jsonify
 from flask_restful import Resource, Api, fields
 from flask_restful_swagger import swagger
 
@@ -41,6 +41,7 @@ class ConfigurationRequestModel:
 class ConfigurationResponseModel:
     resource_fields = {
         'agent_count': fields.Integer,
+        'agent_flavor': fields.String,
         'agent_image': fields.String,
         'public_network': fields.String,
         'stack_created': fields.Boolean,
@@ -62,6 +63,7 @@ class Configure(Resource):
     )
     def get(self):
         return jsonify({'agent_count': storperf.agent_count,
+                        'agent_flavor': storperf.agent_flavor,
                         'agent_image': storperf.agent_image,
                         'public_network': storperf.public_network,
                         'volume_size': storperf.volume_size,
@@ -92,6 +94,8 @@ class Configure(Resource):
         try:
             if ('agent_count' in request.json):
                 storperf.agent_count = request.json['agent_count']
+            if ('agent_flavor' in request.json):
+                storperf.agent_flavor = request.json['agent_flavor']
             if ('agent_image' in request.json):
                 storperf.agent_image = request.json['agent_image']
             if ('public_network' in request.json):
@@ -102,6 +106,7 @@ class Configure(Resource):
             storperf.create_stack()
 
             return jsonify({'agent_count': storperf.agent_count,
+                            'agent_flavor': storperf.agent_flavor,
                             'agent_image': storperf.agent_image,
                             'public_network': storperf.public_network,
                             'volume_size': storperf.volume_size,
@@ -154,16 +159,16 @@ class Job(Resource):
                 "description": "The UUID of the workload in the format "
                 "NNNNNNNN-NNNN-NNNN-NNNN-NNNNNNNNNNNN",
                 "required": True,
-                "type": "string",
+                "metrics_type": "string",
                 "allowMultiple": False,
                 "paramType": "query"
             },
             {
-                "name": "type",
-                "description": "The type of metrics to report.  May be "
+                "name": "metrics_type",
+                "description": "The metrics_type of metrics to report.  May be "
                 "metrics (default), or metadata",
                 "required": False,
-                "type": "string",
+                "metrics_type": "string",
                 "allowMultiple": False,
                 "paramType": "query"
             }
@@ -181,19 +186,19 @@ class Job(Resource):
     )
     def get(self):
 
-        type = "metrics"
-        if request.args.get('type'):
-            type = request.args.get('type')
+        metrics_type = "metrics"
+        if request.args.get('metrics_type'):
+            metrics_type = request.args.get('metrics_type')
 
         workload_id = request.args.get('id')
 
-        if type == "metrics":
+        if metrics_type == "metrics":
             return jsonify(storperf.fetch_results(workload_id))
 
-        if type == "metadata":
+        if metrics_type == "metadata":
             return jsonify(storperf.fetch_metadata(workload_id))
 
-        if type == "status":
+        if metrics_type == "status":
             return jsonify(storperf.fetch_job_status(workload_id))
 
     @swagger.operation(
index a06c847..c758ecd 100644 (file)
@@ -14,7 +14,7 @@ parameters:
     type: string
     constraints:
         - custom_constraint: neutron.network
-  flavor:
+  agent_flavor:
     type: string
     default: "storperf"
   agent_image:
@@ -47,7 +47,7 @@ resources:
         properties: {
           public_network: {get_param: public_network},
           agent_network: {get_resource: storperf_network},
-          flavor: {get_param: flavor},
+          flavor: {get_param: agent_flavor},
           image: {get_param: agent_image},
           storperf_open_security_group: {get_resource: storperf_open_security_group},
           key_name: {get_resource: storperf_key_pair},
index 5432ece..fb3e269 100644 (file)
@@ -137,6 +137,23 @@ class StorPerfMaster(object):
             'public_network',
             value)
 
+    @property
+    def agent_flavor(self):
+        return self.configuration_db.get_configuration_value(
+            'stack',
+            'agent_flavor')
+
+    @agent_flavor.setter
+    def agent_flavor(self, value):
+        if (self.stack_id is not None):
+            raise ParameterError(
+                "ERROR: Cannot change flavor after stack is created")
+
+        self.configuration_db.set_configuration_value(
+            'stack',
+            'agent_flavor',
+            value)
+
     @property
     def stack_id(self):
         return self.configuration_db.get_configuration_value(
@@ -380,6 +397,7 @@ class StorPerfMaster(object):
         heat_parameters['agent_count'] = self.agent_count
         heat_parameters['volume_size'] = self.volume_size
         heat_parameters['agent_image'] = self.agent_image
+        heat_parameters['agent_flavor'] = self.agent_flavor
         return heat_parameters
 
     def _attach_to_openstack(self):
index e8b7188..dda616b 100644 (file)
 from storperf.db.configuration_db import ConfigurationDB
 import os
 import unittest
+import sqlite3
 
 
 class ConfigurationDBTest(unittest.TestCase):
 
     def setUp(self):
-        ConfigurationDB.db_name = __name__ + ".db"
-        try:
-            os.remove(ConfigurationDB.db_name)
-        except OSError:
-            pass
-
+        ConfigurationDB.db_name = "file::memory:?cache=shared"
+        db = sqlite3.connect(ConfigurationDB.db_name)
         self.config_db = ConfigurationDB()
 
     def test_create_key(self):
index 2dc810d..c67e3c4 100644 (file)
@@ -9,18 +9,15 @@
 
 from storperf.db.configuration_db import ConfigurationDB
 from storperf.storperf_master import StorPerfMaster
-import os
 import unittest
+import sqlite3
 
 
 class StorPerfMasterTest(unittest.TestCase):
 
     def setUp(self):
-        ConfigurationDB.db_name = __name__ + ".db"
-        try:
-            os.remove(ConfigurationDB.db_name)
-        except OSError:
-            pass
+        ConfigurationDB.db_name = "file::memory:?cache=shared"
+        db = sqlite3.connect(ConfigurationDB.db_name)
         self.storperf = StorPerfMaster()
 
     def test_agent_count(self):
@@ -67,3 +64,12 @@ class StorPerfMasterTest(unittest.TestCase):
 
         self.assertEqual(
             expected, actual, "Did not expect: " + str(actual))
+
+    def test_agent_flavor(self):
+        expected = "m1.small"
+
+        self.storperf.agent_flavor = expected
+        actual = self.storperf.agent_flavor
+
+        self.assertEqual(
+            expected, actual, "Did not expect: " + str(actual))