Skip to content

Commit

Permalink
Use symlinks for common template files
Browse files Browse the repository at this point in the history
This patch establishes a convention of using a symlink named "common" in
drivers/{driver}/templates/ that points to drivers/common/templates/.
This has two benefits. First, it lowers the burden of forking a driver
by allowing drivers/common/templates/ to be copied over the symlink,
rather than having to update all of the paths in the templates and
driver code.  Second, it shortens the paths used, which makes things
cleaner.

Change-Id: I9176ec03905d0a87a43ba6bedf1f768b2b316125
Partially-implements: blueprint bay-drivers
  • Loading branch information
dragorosson committed Aug 10, 2016
1 parent a72817c commit 748cf13
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions magnum/drivers/k8s_coreos_v1/template_def.py
Expand Up @@ -129,9 +129,9 @@ class CoreOSK8sTemplateDefinition(K8sTemplateDefinition):

def get_env_files(self, baymodel):
if baymodel.master_lb_enabled:
return ['../../common/templates/environments/with_master_lb.yaml']
return ['common/environments/with_master_lb.yaml']
else:
return ['../../common/templates/environments/no_master_lb.yaml']
return ['common/environments/no_master_lb.yaml']

@property
def template_path(self):
Expand Down
1 change: 1 addition & 0 deletions magnum/drivers/k8s_coreos_v1/templates/common
4 changes: 2 additions & 2 deletions magnum/drivers/k8s_fedora_atomic_v1/template_def.py
Expand Up @@ -150,9 +150,9 @@ def get_params(self, context, baymodel, bay, **kwargs):

def get_env_files(self, baymodel):
if baymodel.master_lb_enabled:
return ['../../common/templates/environments/with_master_lb.yaml']
return ['common/environments/with_master_lb.yaml']
else:
return ['../../common/templates/environments/no_master_lb.yaml']
return ['common/environments/no_master_lb.yaml']

@property
def template_path(self):
Expand Down
1 change: 1 addition & 0 deletions magnum/drivers/k8s_fedora_atomic_v1/templates/common
Expand Up @@ -268,7 +268,7 @@ resources:
config:
str_replace:
params:
$configure_docker_storage_driver: {get_file: ../../common/templates/fragments/configure_docker_storage_driver_atomic.sh}
$configure_docker_storage_driver: {get_file: common/fragments/configure_docker_storage_driver_atomic.sh}
template: {get_file: fragments/configure-docker-storage.sh}

configure_etcd:
Expand Down
4 changes: 2 additions & 2 deletions magnum/drivers/k8s_fedora_atomic_v1/templates/kubeminion.yaml
Expand Up @@ -275,14 +275,14 @@ resources:
config:
str_replace:
params:
$configure_docker_storage_driver: {get_file: ../../common/templates/fragments/configure_docker_storage_driver_atomic.sh}
$configure_docker_storage_driver: {get_file: common/fragments/configure_docker_storage_driver_atomic.sh}
template: {get_file: fragments/configure-docker-storage.sh}

configure_docker_registry:
type: OS::Heat::SoftwareConfig
properties:
group: ungrouped
config: {get_file: ../../common/templates/fragments/configure-docker-registry.sh}
config: {get_file: common/fragments/configure-docker-registry.sh}

configure_kubernetes_minion:
type: OS::Heat::SoftwareConfig
Expand Down
4 changes: 2 additions & 2 deletions magnum/drivers/mesos_ubuntu_v1/template_def.py
Expand Up @@ -83,9 +83,9 @@ def get_params(self, context, baymodel, bay, **kwargs):

def get_env_files(self, baymodel):
if baymodel.master_lb_enabled:
return ['../../common/templates/environments/with_master_lb.yaml']
return ['common/environments/with_master_lb.yaml']
else:
return ['../../common/templates/environments/no_master_lb.yaml']
return ['common/environments/no_master_lb.yaml']

@property
def template_path(self):
Expand Down
1 change: 1 addition & 0 deletions magnum/drivers/mesos_ubuntu_v1/templates/common
4 changes: 2 additions & 2 deletions magnum/drivers/swarm_fedora_atomic_v1/template_def.py
Expand Up @@ -112,9 +112,9 @@ def get_params(self, context, baymodel, bay, **kwargs):

def get_env_files(self, baymodel):
if baymodel.master_lb_enabled:
return ['../../common/templates/environments/with_master_lb.yaml']
return ['common/environments/with_master_lb.yaml']
else:
return ['../../common/templates/environments/no_master_lb.yaml']
return ['common/environments/no_master_lb.yaml']

@property
def template_path(self):
Expand Down
1 change: 1 addition & 0 deletions magnum/drivers/swarm_fedora_atomic_v1/templates/common
Expand Up @@ -251,7 +251,7 @@ resources:
config:
str_replace:
params:
$configure_docker_storage_driver: {get_file: ../../common/templates/fragments/configure_docker_storage_driver_atomic.sh}
$configure_docker_storage_driver: {get_file: common/fragments/configure_docker_storage_driver_atomic.sh}
template: {get_file: fragments/configure-docker-storage.sh}

make_cert:
Expand Down
Expand Up @@ -222,14 +222,14 @@ resources:
config:
str_replace:
params:
$configure_docker_storage_driver: {get_file: ../../common/templates/fragments/configure_docker_storage_driver_atomic.sh}
$configure_docker_storage_driver: {get_file: common/fragments/configure_docker_storage_driver_atomic.sh}
template: {get_file: fragments/configure-docker-storage.sh}

configure_docker_registry:
type: OS::Heat::SoftwareConfig
properties:
group: ungrouped
config: {get_file: ../../common/templates/fragments/configure-docker-registry.sh}
config: {get_file: common/fragments/configure-docker-registry.sh}

write_docker_service:
type: "OS::Heat::SoftwareConfig"
Expand Down
10 changes: 5 additions & 5 deletions magnum/tests/unit/conductor/handlers/test_k8s_bay_conductor.py
Expand Up @@ -178,7 +178,7 @@ def _test_extract_template_definition(

self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -246,7 +246,7 @@ def test_extract_template_definition_with_registry(

self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_extract_template_definition_coreos_with_disovery(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_extract_template_definition_coreos_no_discoveryurl(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -518,7 +518,7 @@ def test_extract_template_definition_without_discovery_url(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)
reqget.assert_called_once_with('http://etcd/test?size=1')

Expand Down
Expand Up @@ -122,7 +122,7 @@ def test_extract_template_definition_all_values(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('magnum.objects.BayModel.get_by_uuid')
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_extract_template_definition_only_required(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('magnum.objects.BayModel.get_by_uuid')
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_extract_template_definition_with_lb(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/with_master_lb.yaml'],
['common/environments/with_master_lb.yaml'],
env_files)

@patch('magnum.objects.BayModel.get_by_uuid')
Expand Down Expand Up @@ -267,7 +267,7 @@ def test_extract_template_definition_multi_master(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/with_master_lb.yaml'],
['common/environments/with_master_lb.yaml'],
env_files)

@patch('magnum.conductor.utils.retrieve_baymodel')
Expand Down
10 changes: 5 additions & 5 deletions magnum/tests/unit/conductor/handlers/test_swarm_bay_conductor.py
Expand Up @@ -128,7 +128,7 @@ def test_extract_template_definition_all_values(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_extract_template_definition_with_registry(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_extract_template_definition_only_required(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/no_master_lb.yaml'],
['common/environments/no_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -300,7 +300,7 @@ def test_extract_template_definition_with_lb(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/with_master_lb.yaml'],
['common/environments/with_master_lb.yaml'],
env_files)

@patch('requests.get')
Expand Down Expand Up @@ -357,7 +357,7 @@ def test_extract_template_definition_multi_master(
}
self.assertEqual(expected, definition)
self.assertEqual(
['../../common/templates/environments/with_master_lb.yaml'],
['common/environments/with_master_lb.yaml'],
env_files)

@patch('magnum.conductor.utils.retrieve_baymodel')
Expand Down

1 comment on commit 748cf13

@jcaffet
Copy link
Contributor

@jcaffet jcaffet commented on 748cf13 Aug 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am not sure this commit fully works as it breaks my pip setup.py install phase.
Messages like :
error: can't copy 'magnum/drivers/mesos_ubuntu_v1/templates/common': doesn't exist or not a regular file
Tested either on Ubuntu 14.04/16.04, also breaks the dockerfile build provided in this repo.
Hope it helps.

Please sign in to comment.