Permalink
Browse files

Add --force option to DTRS add commands

Updates objects that already exist.
  • Loading branch information...
1 parent 7757032 commit 2e23bbc13ab0c6577c96d0c86e9ad0d603f15a2d @labisso labisso committed Jan 16, 2013
Showing with 41 additions and 3 deletions.
  1. +28 −3 ceiclient/commands.py
  2. +1 −0 ceiclient/tests/test_commands.py
  3. +12 −0 ceiclient/tests/test_integration.py
View
@@ -60,6 +60,7 @@ def __init__(self, subparsers):
parser = subparsers.add_parser(self.name)
parser.add_argument('dt_name', action='store', help='The name of the DT to be added.')
parser.add_argument('--definition', dest='dt_def_file', action='store', help='Set the DT definition to use.')
+ parser.add_argument('--force', '-f', help="Update the DT if it exists", action='store_true')
@staticmethod
def execute(client, opts):
@@ -72,7 +73,15 @@ def execute(client, opts):
except Exception, e:
raise CeiClientError("Problem reading DT definition file %s: %s" % (opts.dt_def_file, e))
- client.add_dt(opts.caller, opts.dt_name, dt_def)
+ try:
+ client.add_dt(opts.caller, opts.dt_name, dt_def)
+ except WriteConflictError:
+ if opts.force:
+ client.update_dt(opts.caller, opts.dt_name, dt_def)
+ return "Updated DT %s for user %s" % (opts.dt_name, opts.caller)
+ else:
+ raise
+
return "Added DT %s for user %s" % (opts.dt_name, opts.caller)
@@ -147,6 +156,7 @@ def __init__(self, subparsers):
parser = subparsers.add_parser(self.name)
parser.add_argument('site_name', action='store', help='The name of the site to be added.')
parser.add_argument('--definition', dest='site_def_file', action='store', help='Set the site definition to use.')
+ parser.add_argument('--force', '-f', help="Update the site if it exists", action='store_true')
@staticmethod
def execute(client, opts):
@@ -159,7 +169,14 @@ def execute(client, opts):
except Exception, e:
raise CeiClientError("Problem reading site definition file %s: %s" % (opts.site_def_file, e))
- client.add_site(opts.site_name, site_def)
+ try:
+ client.add_site(opts.site_name, site_def)
+ except WriteConflictError:
+ if opts.force:
+ client.update_site(opts.site_name, site_def)
+ return "Updated site %s" % opts.site_name
+ else:
+ raise
return "Added site %s" % opts.site_name
@@ -234,6 +251,7 @@ def __init__(self, subparsers):
parser = subparsers.add_parser(self.name)
parser.add_argument('site_name', action='store', help='The name of the site to be added.')
parser.add_argument('--definition', dest='credentials_def_file', action='store', help='Set the credentials definition to use.')
+ parser.add_argument('--force', '-f', help="Update the credential if it exists", action='store_true')
@staticmethod
def execute(client, opts):
@@ -246,7 +264,14 @@ def execute(client, opts):
except Exception, e:
raise CeiClientError("Problem reading credentials definition file %s: %s" % (opts.credentials_def_file, e))
- client.add_credentials(opts.caller, opts.site_name, credentials_def)
+ try:
+ client.add_credentials(opts.caller, opts.site_name, credentials_def)
+ except WriteConflictError:
+ if opts.force:
+ client.update_credentials(opts.caller, opts.site_name, credentials_def)
+ return "Updated credentials of site %s for user %s" % (opts.site_name, opts.caller)
+ else:
+ raise
return "Added credentials of site %s for user %s" % (opts.site_name, opts.caller)
@@ -6,6 +6,7 @@
from ceiclient.commands import AddDomain, DescribeDomain, ListDomains, \
ReconfigureDomain, RemoveDomain
+
class TestCommandParsing:
def setUp(self):
@@ -219,6 +219,10 @@ def test_dtrs_dts(self):
else:
self.fail("Expected failure to add DT that already exists")
+ cmd = "ceictl -x %s -c %s dt add --force %s --definition %s" % (self.exchange, self.user, new_dt_name, dt_file.name)
+ out = subprocess.check_output(cmd, shell=True)
+ self.assertEqual(out.rstrip(), "Updated DT %s for user %s" % (new_dt_name, self.user))
+
cmd = "ceictl -x %s -c %s dt update %s --definition %s" % (self.exchange, self.user, new_dt_name, dt_file.name)
out = subprocess.check_output(cmd, shell=True)
self.assertEqual(out.rstrip(), "Updated DT %s for user %s" % (new_dt_name, self.user))
@@ -318,6 +322,10 @@ def test_dtrs_credentials(self):
else:
self.fail("Expected failure to add site credentials that already exist")
+ cmd = "ceictl -x %s -c %s credentials add --force %s --definition %s" % (self.exchange, self.user, new_site_name, credentials_file.name)
+ out = subprocess.check_output(cmd, shell=True)
+ self.assertEqual(out.rstrip(), "Updated credentials of site %s for user %s" % (new_site_name, self.user))
+
cmd = "ceictl -x %s -c %s credentials update %s --definition %s" % (self.exchange, self.user, new_site_name, credentials_file.name)
out = subprocess.check_output(cmd, shell=True)
self.assertEqual(out.rstrip(), "Updated credentials of site %s for user %s" % (new_site_name, self.user))
@@ -394,6 +402,10 @@ def test_dtrs_sites(self):
else:
self.fail("Expected failure to add a site that already exists")
+ cmd = "ceictl -x %s site add %s --force --definition %s" % (self.exchange, new_site_name, site_file.name)
+ out = subprocess.check_output(cmd, shell=True)
+ self.assertEqual(out.rstrip(), "Updated site %s" % new_site_name)
+
cmd = "ceictl -x %s site update %s --definition %s" % (self.exchange, new_site_name, site_file.name)
out = subprocess.check_output(cmd, shell=True)
self.assertEqual(out.rstrip(), "Updated site %s" % new_site_name)

0 comments on commit 2e23bbc

Please sign in to comment.