Decoupling cobbler and chef-1
Change-Id: Ib23a2e87772005bc5b2ec4e85026331ee28bedce
This commit is contained in:
parent
0deff5f1fe
commit
7bc977aa65
@ -93,7 +93,6 @@ class OsInstallerCheck(base.BaseCheck):
|
||||
'chef',
|
||||
'chef-validator.pem',
|
||||
'client.rb',
|
||||
'first-boot.json',
|
||||
'kickstart_done',
|
||||
'kickstart_start',
|
||||
'network_config',
|
||||
|
@ -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)
|
||||
|
@ -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'
|
||||
},
|
||||
}],
|
||||
|
@ -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'
|
||||
},
|
||||
}],
|
||||
|
@ -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'
|
||||
},
|
||||
}],
|
||||
|
@ -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'
|
||||
},
|
||||
}],
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user