Skip to content

Commit

Permalink
Merge pull request #19 from ggatward/1.2.0_Hotfix
Browse files Browse the repository at this point in the history
1.2.0 hotfix
  • Loading branch information
ggatward authored Dec 11, 2017
2 parents b638cb3 + bf52fa1 commit c098c4c
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Incorrect mapping of days in auto_content.py
- Support for username:token authentication to Artifactory Puppet Forge server
- Email now supports multiple recipients


## [1.2.0] - 2017-12-10
### Added
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ logging:
email:
mailout: True
mailfrom: Satellite 6 <[email protected]>
mailto: [email protected]
mailto:
- [email protected]
export:
dir: /var/sat-export (Directory to export content to - Connected Satellite)
Expand Down Expand Up @@ -308,6 +309,8 @@ puppet-forge-server:
servertype: puppet-forge-server
hostname: puppetforge.example.org
modulepath: /opt/puppet-forge/modules
username: someuser
token: ArtifactoryAPIToken
```

```
Expand All @@ -326,6 +329,8 @@ optional arguments:
path to puppet-forge-server modules
-u USER, --user USER Username to push modules to server as (default is user
running script)
-p PASSWORD --password PASSWORD
Token for Artifactory API authentication
```

### Examples
Expand Down
28 changes: 20 additions & 8 deletions auto_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@


def dates():
# What day is it? (0=Sun -> 6=Sat)
# What day is it? (0=Mon -> 6=Sun)
dayofweek = datetime.datetime.today().weekday()

# Figure out which week of the month we are in
weekofmonth = (datetime.datetime.now().day-1)/7+1

print "Day %s of week %s" % (dayofweek, weekofmonth)

return(dayofweek,weekofmonth)
# Define dictionary mapping 'human readable' days to thier numeric value
days = {'Mon' : 0, 'Tue' : 1, 'Wed' : 2, 'Thu' : 3, 'Fri' : 4, 'Sat' : 5, 'Sun' : 6}

return(dayofweek,weekofmonth,days)


def run_imports(dryrun):
Expand Down Expand Up @@ -98,6 +101,10 @@ def promote_cv(dryrun, lifecycle):


def push_puppet(dryrun):
"""
Performs a push of puppet modules using the DEFAULT puppet-forge-server defined in the
config.yml
"""
print "Pushing puppet modules to puppet-forge server..."

# Set the initial state
Expand Down Expand Up @@ -130,8 +137,9 @@ def clean_cv(dryrun):


def main(args):

### Run import/publish on scheduled day
"""
Performs import/publish/promote/cleanup on scheduled days
"""

# Check for sane input
parser = argparse.ArgumentParser(
Expand All @@ -153,11 +161,12 @@ def main(args):
run_promote = True

# Determine the day of week and week of month for use in our scheduling
(dayofweek, weekofmonth) = dates()
(dayofweek, weekofmonth, days) = dates()


# MONDAYS
# Run promotion first - this ensures content consistency (QA->Prod, Library->QA)
if dayofweek == 1:
if dayofweek == days['Mon']:
if weekofmonth == 4:
run_promote = promote_cv(dryrun, 'Production')

Expand All @@ -167,7 +176,8 @@ def main(args):
run_promote = promote_cv(dryrun, 'Quality')


# Every day, check if there are any imports in our input dir and import them.
# EVERY DAY
# Check if there are any imports in our input dir and import them.
# run_publish will be returned as 'True' if any successful imports were performed.
# If no imports are performed, or they fail, publish can't be triggered.
run_publish = run_imports(dryrun)
Expand All @@ -179,8 +189,10 @@ def main(args):
if args.puppet:
push_puppet(dryrun)


# THURSDAYS
# Run content view cleanup once a month, after we have done all promotions for the month.
if dayofweek == 4:
if dayofweek == days['Thu']:
if weekofmonth == 4:
clean_cv(dryrun)

Expand Down
5 changes: 4 additions & 1 deletion config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ logging:
email:
mailout: True
mailfrom: Satellite 6 <[email protected]>
mailto: [email protected]
mailto:
- [email protected]

export:
dir: /var/sat-export
Expand Down Expand Up @@ -53,3 +54,5 @@ puppet-forge-server:
servertype: puppet-forge-server
hostname: puppetforge.example.org
modulepath: /opt/puppet-forge/modules
username: pfuser
token: ABCdef123ABCded382654
8 changes: 7 additions & 1 deletion helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
PFSERVER = CONFIG['puppet-forge-server']['hostname']
if 'modulepath' in CONFIG['puppet-forge-server']:
PFMODPATH = CONFIG['puppet-forge-server']['modulepath']
if 'username' in CONFIG['puppet-forge-server']:
PFUSER = CONFIG['puppet-forge-server']['username']
else:
PFUSER = runuser
if 'token' in CONFIG['puppet-forge-server']:
PFTOKEN = CONFIG['puppet-forge-server']['token']

# 'Global' Satellite 6 parameters
# Satellite API
Expand Down Expand Up @@ -459,7 +465,7 @@ def mailout(subject, message):
Assumes localhost is configured for SMTP forwarding (postfix)
"""
sender = MAILFROM
receivers = [MAILTO]
receivers = MAILTO

body = 'From: {}\nSubject: {}\n\n{}'.format(sender, subject, message)

Expand Down
21 changes: 13 additions & 8 deletions man/push_puppetforge.8
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ push_puppetforge \- Export puppet forge modules and push to puppet-forge-server
.B push_puppetforge
is a script to push puppet forge modules that have been synchronised using Satellite 6
to an offline puppet forge server that uses the puppet-forge-server rubygem instance:
.br
.br
.I https://github.com/unibet/puppet-forge-server
.LP
The puppet-forge-server instance requires a specific format for the module filesystem that
differst from that used by Satellite 6. To make use of this script, the connected Satellite
must sync the puppet-forge repository, and have that repo included for the
different from that used by Satellite 6. To make use of this script, the connected Satellite
must sync the puppet-forge repository, and have that repo included for the
.BR sat_export (8)
script. The disconnected Satellite must import the puppet modules into an identically named
puppet repository.
.LP
.BR push_puppetforge " will"
export the puppet modules from the disconnected Satellite and use rsync to transfer them to
export the puppet modules from the disconnected Satellite and use rsync to transfer them to
the offline puppet-forge-server instance.

.SH OPTIONS
Expand All @@ -51,7 +51,7 @@ Label of the puppet-forge repository in Satellite to use as the sync source.
.RS 3
Hostname of the puppet-forge-server instance.
.br
The default value is configured in the
The default value is configured in the
.I config.yml
file
.RE
Expand All @@ -65,12 +65,18 @@ Location of the puppet modules on the puppet-forge-server instance. (Default is
.BR "-u", " --user"
.I USER
.RS 3
Username to login to the puppet-forge-server as. Default is the user running the
Username to login to the puppet-forge-server as. Default is the user running the
.B push_puppetforge
script, from the
script, from the
.I SUDO_USER
environment variable.
.RE
.PP
.BR "-p", " --password"
.I PASSWORD
.RS 3
API Token for user to post modules to Artifactory. Ignored if servertype is puppet-forge-server.
.RE

.SH FILES
.B Main Configuration
Expand All @@ -89,4 +95,3 @@ environment variable.

.SH AUTHOR
Geoff Gatward <[email protected]>

6 changes: 4 additions & 2 deletions man/sat6_scripts.8
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ Enable/Disable mailout functionality.
Sender email address envelope.
.RE

.B " mailto: [email protected]
.B " mailto:"
.br
.B " - [email protected]"
.RS
Recipient email address.
List of recipient email addresses.
.RE


Expand Down
17 changes: 13 additions & 4 deletions push_puppetforge.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def splitext(path):
return os.path.splitext(path)


def postModule(moduleTar, moduleInputDir, pfserver, pfmodpath):
def postModule(moduleTar, moduleInputDir, pfserver, pfmodpath, pfuser, pftoken):
"""
Function to push puppet modules using curl to Artifiactory repository
"""
Expand All @@ -129,7 +129,8 @@ def postModule(moduleTar, moduleInputDir, pfserver, pfmodpath):
fileName = moduleInputDir + "/" + moduleTar

# Put the files using curl (need to clean this up)
subprocess.call(['curl', '-XPUT', url, '-T', fileName])
authtoken = pfuser + ":" + pftoken
subprocess.call(['curl', '-u', authtoken, '-XPUT', url, '-T', fileName])


def main(args):
Expand Down Expand Up @@ -160,6 +161,8 @@ def main(args):
required=False)
parser.add_argument('-u', '--user', help='Username to push modules to server as (default is user running script)',
required=False)
parser.add_argument('-p', '--password', help='Password (token) for username to push modules to Artifactory',
required=False)
args = parser.parse_args()

# Set our script variables from the input args
Expand Down Expand Up @@ -202,7 +205,13 @@ def main(args):
if args.user:
pfuser = args.user
else:
pfuser = runuser
pfuser = helpers.PFUSER

# Read in the token for Artifiactory
if args.password:
pftoken = args.password
else:
pftoken = helpers.PFTOKEN

# Record where we are running from
script_dir = str(os.getcwd())
Expand Down Expand Up @@ -263,7 +272,7 @@ def main(args):
# Method for posting to Artifactory repository
for module in os.listdir(export_dir):
print("Posing: " + module)
postModule(module, export_dir, pfserver, modpath)
postModule(module, export_dir, pfserver, modpath, pfuser, pftoken)

else:
print("Unknown puppet-forge server type defined")
Expand Down

0 comments on commit c098c4c

Please sign in to comment.