From f4f59e97cc35cb5dea70a336c9a1191df55ce09c Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Thu, 17 Dec 2015 18:30:16 +0500 Subject: [PATCH] Fix naming of external services (e.g. specified by rancher.services_include) Add container_name key to service configuration. --- compose/project.go | 15 ++++++++++++++- config/disk.go | 1 - tests/integration/assets/test_01/cloud-config.yml | 2 ++ tests/integration/rostest/test_01_cloud_config.py | 5 +++++ tests/integration/rostest/util.py | 4 ++-- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/compose/project.go b/compose/project.go index 106c7966..6a0b72b9 100644 --- a/compose/project.go +++ b/compose/project.go @@ -94,6 +94,19 @@ func addServices(p *project.Project, enabled map[interface{}]interface{}, config return enabled } +func adjustContainerNames(m map[interface{}]interface{}) map[interface{}]interface{} { + for k, v := range m { + if k, ok := k.(string); ok { + if v, ok := v.(map[interface{}]interface{}); ok { + if _, ok := v["container_name"]; !ok { + v["container_name"] = k + } + } + } + } + return m +} + func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Project, error) { projectEvents := make(chan project.Event) enabled := map[interface{}]interface{}{} @@ -135,7 +148,7 @@ func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Proj log.Errorf("Failed to parse YAML configuration: %s : %v", service, err) continue } - bytes, err = yaml.Marshal(config.StringifyValues(m)) + bytes, err = yaml.Marshal(adjustContainerNames(config.StringifyValues(m))) if err != nil { log.Errorf("Failed to marshal YAML configuration: %s : %v", service, err) continue diff --git a/config/disk.go b/config/disk.go index 3d138694..9697c4ee 100644 --- a/config/disk.go +++ b/config/disk.go @@ -194,7 +194,6 @@ func amendContainerNames(c *CloudConfig) (*CloudConfig, error) { c.Rancher.Services, } { for k, v := range scm { - v.Name = k v.ContainerName = k } } diff --git a/tests/integration/assets/test_01/cloud-config.yml b/tests/integration/assets/test_01/cloud-config.yml index 5e9a4bfc..20175b16 100644 --- a/tests/integration/assets/test_01/cloud-config.yml +++ b/tests/integration/assets/test_01/cloud-config.yml @@ -3,6 +3,8 @@ rancher: environment: ETCD_DISCOVERY: https://discovery.etcd.io/c2c219023108cda9529364d6d983fe13 FLANNEL_NETWORK: 10.244.0.0/16 + services_include: + kernel-headers: true network: interfaces: eth1: diff --git a/tests/integration/rostest/test_01_cloud_config.py b/tests/integration/rostest/test_01_cloud_config.py index 19755fe4..e95b75bf 100644 --- a/tests/integration/rostest/test_01_cloud_config.py +++ b/tests/integration/rostest/test_01_cloud_config.py @@ -63,6 +63,11 @@ def test_dhcpcd(qemu, cloud_config): assert v.find('dhcpcd -M') != -1 +@pytest.mark.timeout(40) +def test_services_include(qemu, cloud_config): + u.wait_for_ssh(qemu, ssh_command, ['docker inspect kernel-headers >/dev/null 2>&1']) + + @pytest.mark.timeout(40) def test_docker_tls_args(qemu, cloud_config): u.wait_for_ssh(qemu, ssh_command) diff --git a/tests/integration/rostest/util.py b/tests/integration/rostest/util.py index 7cc25ffe..4dee6045 100644 --- a/tests/integration/rostest/util.py +++ b/tests/integration/rostest/util.py @@ -76,11 +76,11 @@ def flush_out(stdout, substr='RancherOS '): @pytest.mark.timeout(10) -def wait_for_ssh(qemu, ssh_command=['./scripts/ssh', '--qemu']): +def wait_for_ssh(qemu, ssh_command=['./scripts/ssh', '--qemu'], command=['docker version >/dev/null 2>&1']): i = 0 assert qemu.returncode is None print('\nWaiting for ssh and docker... ' + str(i)) - while subprocess.call(ssh_command + ['docker version >/dev/null 2>&1']) != 0: + while subprocess.call(ssh_command + command) != 0: i += 1 print('\nWaiting for ssh and docker... ' + str(i)) time.sleep(1)