Skip to content

Commit 9b94245

Browse files
committed
Publish/Promote datestamps
1 parent 6988ce6 commit 9b94245

4 files changed

Lines changed: 110 additions & 9 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ Publishes new content to the Library environment. The following can be published
351351
The dry run (-d) option can be used to see what would be published for a
352352
given command input.
353353

354+
Each time a content view is published or promoted, a datestamp is recorded so that
355+
the last publish/promote date can be viewed with the (-l) option. Note that this
356+
datestamp is only updated by this script - it does NOT record publish/promote via
357+
the WebUI or Hammer CLI.
358+
354359
The defaults are configured in the main config.yml file in a YAML block like this:
355360
```
356361
publish:
@@ -371,6 +376,7 @@ optional arguments:
371376
-o ORG, --org ORG Organization (Uses default if not specified)
372377
-a, --all Publish ALL content views
373378
-d, --dryrun Dry Run - Only show what will be published
379+
-l, --last Display last promotions
374380
```
375381

376382
### Examples
@@ -394,6 +400,11 @@ The following can be promoted:
394400
The dry run (-d) option can be used to see what would be promoted for a
395401
given command input.
396402

403+
Each time a content view is published or promoted, a datestamp is recorded so that
404+
the last publish/promote date can be viewed with the (-l) option. Note that this
405+
datestamp is only updated by this script - it does NOT record publish/promote via
406+
the WebUI or Hammer CLI.
407+
397408
The defaults are configured in the main config.yml file in a YAML block like this:
398409
```
399410
promotion:
@@ -425,6 +436,7 @@ optional arguments:
425436
-o ORG, --org ORG Organization (Uses default if not specified)
426437
-a, --all Promote ALL content views
427438
-d, --dryrun Dry Run - Only show what will be promoted
439+
-l, --last Display last promotions
428440
```
429441

430442
### Examples

promote_content_views.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
"""
1313
#pylint: disable-msg=R0912,R0913,R0914,R0915
1414

15-
import sys, argparse
15+
import sys
16+
import os
17+
import argparse
18+
import datetime
19+
import pickle
1620
import simplejson as json
1721
import helpers
1822

@@ -174,19 +178,28 @@ def main(args):
174178
# Who is running this script?
175179
runuser = helpers.who_is_running()
176180

181+
# Set the base dir of the script and where the var data is
182+
global dir
183+
global vardir
184+
dir = os.path.dirname(__file__)
185+
vardir = os.path.join(dir, 'var')
186+
# confdir = os.path.join(dir, 'config')
187+
177188
# Check for sane input
178189
parser = argparse.ArgumentParser(
179190
description='Promotes content views for specified organization to the target environment.')
180191
group = parser.add_mutually_exclusive_group()
181192
# pylint: disable=bad-continuation
182193
parser.add_argument('-e', '--env', help='Target Environment (e.g. Development, Quality, Production)',
183-
required=True)
194+
required=False)
184195
parser.add_argument('-o', '--org', help='Organization (Uses default if not specified)',
185196
required=False)
186197
group.add_argument('-a', '--all', help='Promote ALL content views', required=False,
187198
action="store_true")
188199
parser.add_argument('-d', '--dryrun', help='Dry Run - Only show what will be promoted',
189200
required=False, action="store_true")
201+
parser.add_argument('-l', '--last', help='Display last promotions', required=False,
202+
action="store_true")
190203

191204
args = parser.parse_args()
192205

@@ -202,14 +215,36 @@ def main(args):
202215
target_env = args.env
203216
dry_run = args.dryrun
204217

218+
# Load the promotion history
219+
if not os.path.exists(vardir + '/promotions.pkl'):
220+
if not os.path.exists(vardir):
221+
os.makedirs(vardir)
222+
phistory = {}
223+
else:
224+
phistory = pickle.load(open(vardir + '/promotions.pkl', 'rb'))
225+
226+
# Read the promotion history if --last requested
227+
if args.last:
228+
if phistory:
229+
print 'Last promotions:'
230+
for lenv, time in phistory.iteritems():
231+
print lenv, time
232+
else:
233+
print 'No promotions recorded'
234+
sys.exit(-1)
235+
236+
# Error if no environment to promote to is given
237+
if args.env is None:
238+
parser.error('--env is required')
239+
205240
promote_list = []
206241
if not args.all:
207242
for x in helpers.CONFIG['promotion']:
208243
if helpers.CONFIG['promotion'][x]['name'] == target_env:
209244
promote_list = helpers.CONFIG['promotion'][x]['content_views']
210245

211246
if not promote_list:
212-
msg = "Cannot find promotion configuration for '" + target_env
247+
msg = "Cannot find promotion configuration for '" + target_env + "'"
213248
helpers.log_msg(msg, 'ERROR')
214249
sys.exit(-1)
215250

@@ -230,6 +265,10 @@ def main(args):
230265
(task_list, ref_list, task_name) = promote(target_env, ver_list, ver_descr, ver_version,
231266
env_list, prior_list, dry_run)
232267

268+
# Add/Update the promotion history dictionary so we can check when we last promoted
269+
phistory[target_env] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d')
270+
pickle.dump(phistory, open(vardir + '/promotions.pkl', 'wb'))
271+
233272
# Monitor the status of the promotion tasks
234273
helpers.watch_tasks(task_list, ref_list, task_name)
235274

publish_content_views.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
"""
1313
#pylint: disable-msg=R0912,R0913,R0914,R0915
1414

15-
import sys, argparse
15+
import sys
16+
import os
17+
import argparse
18+
import datetime
19+
import pickle
1620
import simplejson as json
1721
import helpers
1822

@@ -112,6 +116,13 @@ def main(args):
112116
# Who is running this script?
113117
runuser = helpers.who_is_running()
114118

119+
# Set the base dir of the script and where the var data is
120+
global dir
121+
global vardir
122+
dir = os.path.dirname(__file__)
123+
vardir = os.path.join(dir, 'var')
124+
confdir = os.path.join(dir, 'config')
125+
115126
# Check for sane input
116127
parser = argparse.ArgumentParser(
117128
description='Publishes content views for specified organization.')
@@ -123,12 +134,15 @@ def main(args):
123134
action="store_true")
124135
parser.add_argument('-d', '--dryrun', help='Dry Run - Only show what will be published',
125136
required=False, action="store_true")
137+
parser.add_argument('-l', '--last', help='Display last promotions', required=False,
138+
action="store_true")
126139

127140
args = parser.parse_args()
128141

129142
# Log the fact we are starting
130-
msg = "-------- Content view publish started by " + runuser + " -----------"
131-
helpers.log_msg(msg, 'INFO')
143+
if not args.last:
144+
msg = "-------- Content view publish started by " + runuser + " -----------"
145+
helpers.log_msg(msg, 'INFO')
132146

133147
# Set our script variables from the input args
134148
if args.org:
@@ -137,6 +151,25 @@ def main(args):
137151
org_name = helpers.ORG_NAME
138152
dry_run = args.dryrun
139153

154+
# Load the promotion history
155+
if not os.path.exists(vardir + '/promotions.pkl'):
156+
if not os.path.exists(vardir):
157+
os.makedirs(vardir)
158+
phistory = {}
159+
else:
160+
phistory = pickle.load(open(vardir + '/promotions.pkl', 'rb'))
161+
162+
# Read the promotion history if --last requested
163+
if args.last:
164+
if phistory:
165+
print 'Last promotions:'
166+
for lenv, time in phistory.iteritems():
167+
print lenv, time
168+
else:
169+
print 'No promotions recorded'
170+
sys.exit(-1)
171+
172+
140173
publish_list = []
141174
if not args.all:
142175
publish_list = helpers.CONFIG['publish']['content_views']
@@ -158,6 +191,10 @@ def main(args):
158191
# Publish the content views. Returns a list of task IDs.
159192
(task_list, ref_list, task_name) = publish(ver_list, ver_descr, ver_version, dry_run, runuser)
160193

194+
# Add/Update the promotion history dictionary so we can check when we last promoted
195+
phistory['Library'] = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d')
196+
pickle.dump(phistory, open(vardir + '/promotions.pkl', 'wb'))
197+
161198
# Monitor the status of the publish tasks
162199
helpers.watch_tasks(task_list, ref_list, task_name)
163200

sat_import.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def count_packages(repo_id):
173173
return numpkg, numerrata
174174

175175

176-
def check_counts(org_id, package_count):
176+
def check_counts(org_id, package_count, count):
177177
"""
178178
Verify the number of pkgs/errutum in each repo match the sync host.
179179
Input is a dictionary loaded from a pickle that was created on the sync
@@ -205,19 +205,30 @@ def check_counts(org_id, package_count):
205205
# Set the output colour of the table entry based on the pkg counts
206206
if int(local_pkgs) == int(sync_pkgs):
207207
colour = helpers.GREEN
208+
display = False
208209
elif int(local_pkgs) == 0 and int(sync_pkgs) != 0:
209210
colour = helpers.RED
211+
display = True
210212
elif int(local_pkgs) < int(sync_pkgs):
211213
colour = helpers.YELLOW
214+
display = True
212215
else:
213216
# If local_pkg > sync_pkg - can happen due to 'mirror on sync' option
214217
# - sync host deletes old pkgs. If this is the case we cannot verify
215218
# an exact package status so we'll set BLUE
216219
colour = helpers.BLUE
220+
display = True
217221

218222
# Tuncate the repo label to 70 chars and build the table row
219223
reponame = "{:<70}".format(repo)
220-
table_data.append([colour, repo[:70], str(sync_pkgs), str(local_pkgs), helpers.ENDC])
224+
# Add all counts if it has been requested
225+
if count:
226+
table_data.append([colour, repo[:70], str(sync_pkgs), str(local_pkgs), helpers.ENDC])
227+
else:
228+
# Otherwise only add counts that are non-green (display = True)
229+
if display:
230+
table_data.append([colour, repo[:70], str(sync_pkgs), str(local_pkgs), helpers.ENDC])
231+
221232

222233
msg = '\nRepository package count verification...'
223234
helpers.log_msg(msg, 'INFO')
@@ -273,6 +284,8 @@ def main(args):
273284
required=False, action="store_true")
274285
parser.add_argument('-l', '--last', help='Display the last successful import performed',
275286
required=False, action="store_true")
287+
parser.add_argument('-c', '--count', help='Display all package counts after import',
288+
required=False, action="store_true")
276289
args = parser.parse_args()
277290

278291
# Set our script variables from the input args
@@ -335,7 +348,7 @@ def main(args):
335348
print 'Please publish content views to make new content available.'
336349

337350
# Verify the repository package/erratum counts match the sync host
338-
check_counts(org_id, package_count)
351+
check_counts(org_id, package_count, args.count)
339352

340353
if os.path.exists(helpers.IMPORTDIR + '/puppetforge'):
341354
print 'Offline puppet-forge-server bundle is available to import seperately in '\

0 commit comments

Comments
 (0)