diff --git a/compass/actions/health_check/check_os_installer.py b/compass/actions/health_check/check_os_installer.py index d23903dc..06515412 100644 --- a/compass/actions/health_check/check_os_installer.py +++ b/compass/actions/health_check/check_os_installer.py @@ -93,7 +93,6 @@ class OsInstallerCheck(base.BaseCheck): 'chef', 'chef-validator.pem', 'client.rb', - 'first-boot.json', 'kickstart_done', 'kickstart_start', 'network_config', diff --git a/compass/config_management/installers/plugins/chefhandler.py b/compass/config_management/installers/plugins/chefhandler.py index 1b4afb67..6d718b14 100644 --- a/compass/config_management/installers/plugins/chefhandler.py +++ b/compass/config_management/installers/plugins/chefhandler.py @@ -154,6 +154,20 @@ class Installer(package_installer.Installer): """get client name.""" return cls._get_node_name(fullname, target_system) + def _update_host_attributes(self, config, target_system): + """chef manage node attributes.""" + from chef import Node + roles = config['roles'] + node_name = "%s.%s" % (target_system, config['fullname']) + node = Node(node_name, api=self.api_) + node['cluster'] = self._cluster_databag_name( + config['clusterid'], + target_system) + + for role in roles: + node.run_list.append('role[%s]' % role) + node.save() + @classmethod def _get_node_name(cls, fullname, target_system): """get node name.""" @@ -163,10 +177,6 @@ class Installer(package_installer.Installer): """get os installer config.""" return { '%s_url' % self.NAME: self.installer_url_, - 'run_list': ','.join( - ['"role[%s]"' % role for role in config['roles'] if role]), - 'cluster_databag': self._cluster_databag_name( - config['clusterid'], target_system), 'chef_client_name': self._get_client_name( config['fullname'], target_system), 'chef_node_name': self._get_node_name( @@ -310,6 +320,7 @@ class Installer(package_installer.Installer): """reinstall host.""" self._clean_client(hostid, config, target_system, **kwargs) self._clean_node(hostid, config, target_system, **kwargs) + self._update_host_attributes(config, target_system) def update_host_config(self, hostid, config, target_system, **kwargs): """update host cnfig.""" @@ -337,5 +348,6 @@ class Installer(package_installer.Installer): bag_item.save() + self._update_host_attributes(config, target_system) package_installer.register(Installer) diff --git a/compass/tests/actions/deploy/data/test1 b/compass/tests/actions/deploy/data/test1 index 800498c9..c3ab82ea 100644 --- a/compass/tests/actions/deploy/data/test1 +++ b/compass/tests/actions/deploy/data/test1 @@ -210,11 +210,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-single-controller]","role[os-compute-worker]","role[os-network]"', 'ignore_proxy': '127.0.0.1,localhost,host1.1,192.168.20.100', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host1.1', - 'cluster_databag': 'openstack_1', 'chef_node_name': u'openstack.host1.1' }, }], diff --git a/compass/tests/actions/deploy/data/test2 b/compass/tests/actions/deploy/data/test2 index ba0ce63a..134c3959 100644 --- a/compass/tests/actions/deploy/data/test2 +++ b/compass/tests/actions/deploy/data/test2 @@ -226,11 +226,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-single-controller]"', 'ignore_proxy': '127.0.0.1,localhost,host1.1,192.168.20.100,host2.1,192.168.20.101', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host1.1', - 'cluster_databag': 'openstack_1', 'chef_node_name': 'openstack.host1.1' }, },{ @@ -260,11 +258,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-compute-worker]","role[os-network]"', 'ignore_proxy': '127.0.0.1,localhost,host1.1,192.168.20.100,host2.1,192.168.20.101', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host2.1', - 'cluster_databag': 'openstack_1', 'chef_node_name': 'openstack.host2.1' }, }], diff --git a/compass/tests/actions/deploy/data/test3 b/compass/tests/actions/deploy/data/test3 index b33943cc..7ef21ef9 100644 --- a/compass/tests/actions/deploy/data/test3 +++ b/compass/tests/actions/deploy/data/test3 @@ -318,11 +318,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-single-controller]"', 'ignore_proxy': '127.0.0.1,localhost,host1.1,192.168.20.100,host2.1,192.168.20.101', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host1.1', - 'cluster_databag': 'openstack_1', 'chef_node_name': u'openstack.host1.1' }, },{ @@ -352,11 +350,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-compute-worker]","role[os-network]"', 'ignore_proxy': '127.0.0.1,localhost,host1.1,192.168.20.100,host2.1,192.168.20.101', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host2.1', - 'cluster_databag': 'openstack_1', 'chef_node_name': u'openstack.host2.1' }, },{ @@ -386,11 +382,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-single-controller]"', 'ignore_proxy': '127.0.0.1,localhost,host1.2,192.168.20.110,host2.2,192.168.20.111', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host1.2', - 'cluster_databag': 'openstack_2', 'chef_node_name': u'openstack.host1.2' }, },{ @@ -420,11 +414,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-compute-worker]","role[os-network]"', 'ignore_proxy': '127.0.0.1,localhost,host1.2,192.168.20.110,host2.2,192.168.20.111', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host2.2', - 'cluster_databag': 'openstack_2', 'chef_node_name': u'openstack.host2.2' }, }], diff --git a/compass/tests/actions/deploy/data/test4 b/compass/tests/actions/deploy/data/test4 index b19a6fa8..12683596 100644 --- a/compass/tests/actions/deploy/data/test4 +++ b/compass/tests/actions/deploy/data/test4 @@ -210,11 +210,9 @@ cobbler_EXPECTED = { 'tool': 'chef', 'partition': '/home 20%%;/tmp 10%%;/var 30%%;', 'proxy': 'http://192.168.20.254:3128', - 'run_list': '"role[os-dashboard]"', 'ignore_proxy': '127.0.0.1,localhost,host1.1,192.168.20.100', 'ntp_server': '192.168.20.254', 'chef_client_name': 'openstack.host1.1', - 'cluster_databag': 'openstack_1', 'chef_node_name': u'openstack.host1.1' }, }], diff --git a/compass/tests/actions/deploy/test_deploy.py b/compass/tests/actions/deploy/test_deploy.py index 0b8587da..c939f866 100755 --- a/compass/tests/actions/deploy/test_deploy.py +++ b/compass/tests/actions/deploy/test_deploy.py @@ -173,12 +173,13 @@ class TestEndToEnd(unittest2.TestCase): import collections - class _mockDict(collections.Mapping): - """mock dict class.""" + class _mockDataBagItem(collections.Mapping): + """mock databag item class.""" def __init__(in_self, bag, bag_item_name, api): in_self.bag_item_name_ = bag_item_name in_self.config_ = configs.get(bag_item_name, {}) + in_self.run_list = mock.Mock(side_effect=_mockRunList) def __len__(in_self): return len(in_self.config_) @@ -203,13 +204,54 @@ class TestEndToEnd(unittest2.TestCase): """mock save.""" configs[in_self.bag_item_name_] = in_self.config_ + class _mockRunList(collections.Set): + def __init__(in_self, node_name, api): + in_self.node_name = node_name + in_self.config_ = [] + + def __len__(in_self, api): + return len(in_self.config_) + + def __iter__(in_self): + return iter(in_self.config_) + + def __getitem__(in_self): + return in_self.config_ + + def append(in_self, role): + in_self.config_.append(role) + + class _mockNode(collections.Mapping): + """mock node class.""" + + def __init__(in_self, node_name, api): + in_self.node_name_ = node_name + in_self.config_ = configs.get(node_name, {}) + in_self.run_list = mock.Mock(side_effect=_mockRunList) + + def __len__(in_self): + return len(in_self.config_) + + def __iter__(in_self): + return iter(in_self.config_) + + def __getitem__(in_self, name): + return in_self.config_[name] + + def __setitem__(in_self, name, value): + in_self.config_[name] = value + + def save(in_self): + """mock save.""" + configs[in_self.node_name_] = in_self.config_ + self.chef_databagitem_backup_ = chef.DataBagItem - chef.DataBagItem = mock.Mock(side_effect=_mockDict) + chef.DataBagItem = mock.Mock(side_effect=_mockDataBagItem) self.chef_client_backup_ = chef.Client chef.Client = mock.Mock() chef.Client.return_value.delete = mock.Mock() self.chef_node_backup_ = chef.Node - chef.Node = mock.Mock() + chef.Node = mock.Mock(side_effect=_mockNode) chef.Node.return_value.delete = mock.Mock() def _check_chef(self, configs, expected_configs): diff --git a/install/prepare.sh b/install/prepare.sh index c7e4df32..6f059627 100755 --- a/install/prepare.sh +++ b/install/prepare.sh @@ -23,6 +23,7 @@ copygit2dir() git reset --hard remotes/origin/master if [[ -n "$GERRIT_REFSPEC" ]];then git fetch $gerrit_repo $GERRIT_REFSPEC && git checkout FETCH_HEAD + git fetch https://review.openstack.org/stackforge/compass-adapters refs/changes/20/86120/2 && git cherry-pick FETCH_HEAD fi git clean -x -f else @@ -33,6 +34,7 @@ copygit2dir() # project=$(echo $repo|rev|cut -d '/' -f 1|rev) cd $destdir git fetch $gerrit_repo $GERRIT_REFSPEC && git checkout FETCH_HEAD + git fetch https://review.openstack.org/stackforge/compass-adapters refs/changes/20/86120/2 && git cherry-pick FETCH_HEAD fi fi cd $SCRIPT_DIR