Skip to content

Commit

Permalink
Merge pull request #575 from ChandraAddala/enums-feature
Browse files Browse the repository at this point in the history
Enums feature
  • Loading branch information
ChandraAddala committed Dec 11, 2015
2 parents f0f2b69 + c0814f9 commit 8e5d986
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions contrib/enum_metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This project contains some python utilities to work with enum metrics.

### Setup

Get the [blue flood](https://github.com/rackerlabs/blueflood) repo from github. Execute the following commands
Get the [blueflood](https://github.com/rackerlabs/blueflood) repo from github. Execute the following commands

cd $BLUEFLOOD_REPO_LOCATION/contrib/enum_metrics
virtualenv enums
Expand Down Expand Up @@ -38,7 +38,7 @@ excess enum (i.e. if its present in metrics_excess_enums table)
####Delete command

usage: errant_enums.py delete [-h] [--dryrun] -m METRICNAME -t TENANTID
[-e {localhost,qe01,qe02,staging,prod}]
[-e {localhost}]

optional arguments:
-h, --help show this help message and exit
Expand All @@ -49,7 +49,7 @@ excess enum (i.e. if its present in metrics_excess_enums table)
-t TENANTID, --tenantId TENANTID
tenantId corresponding to the metric name to be
deleted
-e {localhost,qe01,qe02,staging,prod}, --env {localhost,qe01,qe02,staging,prod}
-e {localhost}, --env {localhost}
Environment we are pointing to

Example Usage:
Expand All @@ -59,11 +59,11 @@ Example Usage:

####List command

usage: errant_enums.py list [-h] [-e {localhost,qe01,qe02,staging,prod}]
usage: errant_enums.py list [-h] [-e {localhost}]

optional arguments:
-h, --help show this help message and exit
-e {localhost,qe01,qe02,staging,prod}, --env {localhost,qe01,qe02,staging,prod}
-e {localhost}, --env {localhost}
Environment we are pointing to


Expand Down
13 changes: 9 additions & 4 deletions contrib/enum_metrics/enum_metrics/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@


class Config:

parser = SafeConfigParser()
parser.read(os.path.join(os.path.dirname(__file__), '..', 'config.ini'))

def __init__(self, env):
self.env = env

self.parser = SafeConfigParser()
self.parser.read(os.path.join(os.path.dirname(__file__), '..', 'config.ini'))

print self.parser.sections()

def __get_value(self, config_name):
return self.parser.get(self.env, config_name)
return Config.parser.get(self.env, config_name)

def get_cassandra_nodes(self):
return self.__get_value('cassandra_nodes').split(",")

def get_es_nodes(self):
return self.__get_value('es_nodes').split(",")

@staticmethod
def get_environments():
return Config.parser.sections()
9 changes: 2 additions & 7 deletions contrib/enum_metrics/enum_metrics/errant_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import config as cf

LOCALHOST = 'localhost'
QE01 = 'qe01'
QE02 = 'qe02'
STAGING = 'staging'
PROD = 'prod'



def parse_arguments(args):
Expand All @@ -32,10 +29,8 @@ def parse_arguments(args):
delete_parser.add_argument('-t', '--tenantId',
required=True, help='tenantId corresponding to the metric name to be deleted')

environments = [LOCALHOST, QE01, QE02, STAGING, PROD]

for p in [list_parser, delete_parser]:
p.add_argument('-e', '--env', choices=environments,
p.add_argument('-e', '--env', choices=cf.Config.get_environments(),
default=LOCALHOST, help='Environment we are pointing to')

args = parser.parse_args(args)
Expand Down
4 changes: 2 additions & 2 deletions contrib/enum_metrics/test/test_errant_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def test_valid_args_1(self):

def test_valid_args_2(self):
metric_name = 'metric.test'
args = em.parse_arguments(['delete', '--metricName', metric_name, '--tenantId', '836986', '-e', 'qe01'])
args = em.parse_arguments(['delete', '--metricName', metric_name, '--tenantId', '836986', '-e', em.LOCALHOST])

self.assertEquals(args.dryrun, False)
self.assertEquals(args.metricName, metric_name)
self.assertEquals(args.env, em.QE01)
self.assertEquals(args.env, em.LOCALHOST)

def test_valid_args_3(self):
metric_name = 'metric.test'
Expand Down

0 comments on commit 8e5d986

Please sign in to comment.