From 3aabacedc82115829fba39a371ac259668e1d4e0 Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Thu, 3 Dec 2015 21:55:22 -0800 Subject: [PATCH] Separate concerns in pypi_mirror.pp This patch separates the creation of the bandersnatch pypi mirror from the creation of the apache vhost, and parameterizes the data directory in which bandersnatch places its packages. This is done so that we may reuse the pypi_mirror.pp module when building our new unified mirrors, which host pypi assets in a different directory and under a different hostname and URI. This patch should not trigger any changes on the existing mirrors. Change-Id: I55286df53d8dd84ea2377035b830cd92d378ad39 --- modules/openstack_project/manifests/pypi.pp | 30 +++++++++++++++- .../manifests/pypi_mirror.pp | 34 +++---------------- .../bandersnatch.conf.erb} | 2 +- 3 files changed, 35 insertions(+), 31 deletions(-) rename modules/openstack_project/{files/bandersnatch.conf => templates/bandersnatch.conf.erb} (97%) diff --git a/modules/openstack_project/manifests/pypi.pp b/modules/openstack_project/manifests/pypi.pp index 1290f5cced..0580021069 100644 --- a/modules/openstack_project/manifests/pypi.pp +++ b/modules/openstack_project/manifests/pypi.pp @@ -10,7 +10,35 @@ class openstack_project::pypi ( sysadmins => $sysadmins, } + $mirror_root = '/srv/static' + $pypi_root = "${mirror_root}/mirror" + + if ! defined(File[$mirror_root]) { + file { $mirror_root: + ensure => directory, + } + } + class { 'openstack_project::pypi_mirror': - vhost_name => $vhost_name, + data_directory => "${pypi_root}", + require => File[$mirror_root] + } + + include ::httpd + + ::httpd::vhost { $vhost_name: + port => 80, + priority => '50', + docroot => "${pypi_root}/web", + require => Class['Openstack_project::Pypi_mirror'], + } + + file { "${pypi_root}/web/robots.txt": + ensure => present, + owner => 'root', + group => 'root', + mode => '0444', + source => 'puppet:///modules/openstack_project/disallow_robots.txt', + require => Class['Openstack_project::Pypi_mirror'], } } diff --git a/modules/openstack_project/manifests/pypi_mirror.pp b/modules/openstack_project/manifests/pypi_mirror.pp index 50d9a46686..87414e6c19 100644 --- a/modules/openstack_project/manifests/pypi_mirror.pp +++ b/modules/openstack_project/manifests/pypi_mirror.pp @@ -1,45 +1,21 @@ # == Class: openstack_project::pypi_mirror # class openstack_project::pypi_mirror ( - $vhost_name, + $data_directory = '/srv/static/mirror', $cron_frequency = '*/5', ) { - include ::httpd - - if ! defined(File['/srv/static']) { - file { '/srv/static': - ensure => directory, - } - } - - file { '/srv/static/mirror': + file { "${data_directory}": ensure => directory, owner => 'root', group => 'root', } - file { '/srv/static/mirror/web': + file { "${data_directory}/web": ensure => directory, owner => 'root', group => 'root', - require => File['/srv/static/mirror'], - } - - ::httpd::vhost { $vhost_name: - port => 80, - priority => '50', - docroot => '/srv/static/mirror/web', - require => File['/srv/static/mirror/web'], - } - - file { '/srv/static/mirror/web/robots.txt': - ensure => present, - owner => 'root', - group => 'root', - mode => '0444', - source => 'puppet:///modules/openstack_project/disallow_robots.txt', - require => File['/srv/static/mirror/web'], + require => File["${data_directory}"], } package { 'bandersnatch': @@ -49,7 +25,7 @@ class openstack_project::pypi_mirror ( file { '/etc/bandersnatch.conf': ensure => present, - source => 'puppet:///modules/openstack_project/bandersnatch.conf', + content => template('openstack_project/bandersnatch.conf.erb'), } file { '/var/log/bandersnatch': diff --git a/modules/openstack_project/files/bandersnatch.conf b/modules/openstack_project/templates/bandersnatch.conf.erb similarity index 97% rename from modules/openstack_project/files/bandersnatch.conf rename to modules/openstack_project/templates/bandersnatch.conf.erb index ed6d6f0b6b..5332c737fe 100644 --- a/modules/openstack_project/files/bandersnatch.conf +++ b/modules/openstack_project/templates/bandersnatch.conf.erb @@ -1,6 +1,6 @@ [mirror] ; The directory where the mirror data will be stored. -directory = /srv/static/mirror +directory = <%= @data_directory %> ; The PyPI server which will be mirrored. ; master = https://testpypi.python.org