def test_delete(self): name = self.random() r = Role.create(name) r.delete() for n in Role.list(): self.assertNotEqual(n, name) self.assertFalse(Role(name).exists)
def test_get(self): r = Role('test_1') self.assertTrue(r.exists) self.assertEqual(r.description, 'Static test role 1') self.assertEqual(r.run_list, []) self.assertEqual(r.default_attributes['test_attr'], 'default') self.assertEqual(r.default_attributes['nested']['nested_attr'], 1) self.assertEqual(r.override_attributes['test_attr'], 'override')
def test_create(self): name = self.random() r = Role.create(name, description='A test role', run_list=['recipe[foo]'], default_attributes={'attr': 'foo'}, override_attributes={'attr': 'bar'}) self.register(r) self.assertEqual(r.description, 'A test role') self.assertEqual(r.run_list, ['recipe[foo]']) self.assertEqual(r.default_attributes['attr'], 'foo') self.assertEqual(r.override_attributes['attr'], 'bar') r2 = Role(name) self.assertTrue(r2.exists) self.assertEqual(r2.description, 'A test role') self.assertEqual(r2.run_list, ['recipe[foo]']) self.assertEqual(r2.default_attributes['attr'], 'foo') self.assertEqual(r2.override_attributes['attr'], 'bar')
def check_required(): """Check if the required roles are available.""" chef_api = autoconfigure() chef_roles = Role.list(api=chef_api) for role in get_required().values(): if check(role, chef_roles): print(green('Role %s available.') % role) else: print(red('Role %s NOT available.') % role)
def test_create(self): name = self.random() r = Role.create(name, description='A test role', run_list=['recipe[foo]']) self.register(r) self.assertEqual(r.description, 'A test role') self.assertEqual(r.run_list, ['recipe[foo]']) r2 = Role(name) self.assertTrue(r2.exists) self.assertEqual(r2.description, 'A test role') self.assertEqual(r2.run_list, ['recipe[foo]'])
def create_missing(): """Create missing roles on the chef server.""" chef_api = autoconfigure() required = roles.get_required() domain = api.env.get('domain', 'example.com') # Create the role_database. if not roles.check(required.get('role_database')): name = required.get('role_database') description = 'ZEO Server for %s.' % domain run_list = ( "role[mls_zeoserver]", ) default_attributes = { 'domain': domain, } Role.create( name, api=chef_api, description=description, run_list=run_list, default_attributes=default_attributes, ) print(green('Created role %s') % name) # Create the role_frontend. if not roles.check(required.get('role_frontend')): name = required.get('role_frontend') description = 'Frontend Server for %s.' % domain run_list = ( "role[mls_loadbalancer]", ) default_attributes = { 'domain': domain, 'haproxy': { 'app_server_role': required.get('role_worker'), }, 'mls': { 'domain': '.'.join(['mls', domain]), }, } Role.create( name, api=chef_api, description=description, run_list=run_list, default_attributes=default_attributes, ) print(green('Created role %s') % name) # Create the role_worker. if not roles.check(required.get('role_worker')): name = required.get('role_worker') description = 'Application Worker for %s.' % domain run_list = ( "role[mls_application]", ) policy_on = api.env.get('mls_policy_enabled') and 'true' or 'false' default_attributes = { 'domain': domain, 'mls': { 'customizations': api.env.get('mls_customizations', []), 'policy': { 'enabled': policy_on, 'package': api.env.get('mls_policy_package', ''), 'package_url': api.env.get('mls_policy_package_url', ''), }, 'zeo_role': required.get('role_database'), }, } Role.create( name, api=chef_api, description=description, run_list=run_list, default_attributes=default_attributes, ) print(green('Created role %s') % name) # Create the role_staging. if not roles.check(required.get('role_staging')): name = required.get('role_staging') description = 'Staging system for %s.' % domain run_list = ( "role[%s]" % required.get('role_database'), "role[%s]" % required.get('role_worker'), "role[%s]" % required.get('role_frontend'), ) default_attributes = { 'domain': domain, 'haproxy': { 'app_server_role': name, }, 'mls': { 'domain': '.'.join(['staging', domain]), 'zeo_role': name, }, } Role.create( name, api=chef_api, description=description, run_list=run_list, default_attributes=default_attributes, ) print(green('Created role %s') % name)
def create_missing(): """Create missing roles on the chef server.""" chef_api = autoconfigure() required = roles.get_required() domain = api.env.get('domain', 'example.com') # Create the role_base. if not roles.check(required.get('role_base')): name = required.get('role_base') description = 'Plone Application for %s.' % domain run_list = ( "role[base]", "recipe[build-essential]", ) default_attributes = { 'domain': domain, 'haproxy': { 'app_server_role': required.get('role_worker'), 'incoming_address': '127.0.0.1', 'incoming_port': '8300', 'member_port': '8080', }, 'nginx': { 'client_max_body_size': '150m', }, 'plone': { 'client': { 'count': 2, 'eggs': [ "Products.Doormat == 0.9.1", "Products.PloneFormGen == 1.7.12", "Products.RedirectionTool == 1.3.1", "collective.carousel == 1.6.2", "collective.contentleadimage == 1.3.4", "collective.cover == 1.0a6", "collective.googleanalytics == 1.4.3", "mls.apiclient == 1.1.1", "plone.app.multilingual == 1.2.1", "plone.mls.core == 0.4.2", "plone.mls.listing == 0.9.7", "plone.multilingualbehavior == 1.2", ], 'extends': [ 'plone_sites.cfg', ], 'zeo_role': required.get('role_database'), }, 'version': api.env.get('plone_version', '4.3.2'), 'vhost_data_bag': api.env.get('vhost_databag', ''), }, 'python': { 'checksum': PYTHON_MD5, 'configure_options': [ '--prefix=/usr/local', ], 'install_method': 'source', 'prefix_dir': '/usr/local', 'version': '2.7.5', }, 'varnish': { 'listen_address': '127.0.0.1', 'listen_port': '9000', 'backend_port': '8300', 'storage': 'malloc', 'storage_size': '512M', 'vcl_cookbook': 'plone_hosting', 'vcl_source': 'varnish.vcl.erb', } } Role.create( name, api=chef_api, description=description, run_list=run_list, default_attributes=default_attributes, ) print(green('Created role %s') % name) # Create the role_database. if not roles.check(required.get('role_database')): name = required.get('role_database') description = 'ZEO Server for %s.' % domain run_list = ( "role[%s]" % required.get('role_base'), "recipe[plone_hosting::database_server]", ) override_attributes = { 'plone': { 'client': { 'count': 2, } }, } Role.create( name, api=chef_api, description=description, run_list=run_list, override_attributes=override_attributes, ) print(green('Created role %s') % name) # Create the role_frontend. if not roles.check(required.get('role_frontend')): name = required.get('role_frontend') description = 'Frontend Server for %s.' % domain run_list = ( "role[%s]" % required.get('role_base'), "recipe[plone_hosting::load_balancer]", "recipe[plone_hosting::cache_server]", "recipe[plone_hosting::web_server]" ) Role.create( name, api=chef_api, description=description, run_list=run_list, ) print(green('Created role %s') % name) # Create the role_worker. if not roles.check(required.get('role_worker')): name = required.get('role_worker') description = 'Application Worker for %s.' % domain run_list = ( "role[%s]" % required.get('role_base'), "recipe[plone_hosting::app_server]", ) Role.create( name, api=chef_api, description=description, run_list=run_list, ) print(green('Created role %s') % name)
def check(role, roles=None): """Check if a given role is available on the chef server.""" if not roles: chef_api = autoconfigure() roles = Role.list(api=chef_api) return role in roles