def test_Compute___add_database_valid_params_returns_task_id(self): self._add_dummy_node('test1') result = self.svc.Compute___add_database("test1", {"MYSQL_PASS": "******"}) self.assertEqual(result, "task_id") dummy_node = self._get_dummy_node() role_list = dummy_node.get_roles() self.assertEqual([Role.get_by_name("mysqld")], role_list) mysql_pass = ConfigClassParameter.get_by_name("MYSQL_PASS") self.assertEqual("password", mysql_pass.default_value) mysql_host = ConfigClassParameter.get_by_name("MYSQL_HOST") self.assertEqual("test1", mysql_host.default_value)
def model_init(**kwargs): """Set this host to be the Geppetto master and save global config""" for name, value in kwargs.iteritems(): if value: ConfigClassParameter.set_config_parameter(name.upper(), value) master_hostname = network.get_hostname() Master.promote_node(master_hostname) master = get_or_create_node(master_hostname) Override.\ update_or_create_override(master, ConfigClassParameter.get_by_name( ConfigClassParameter.VPX_LABEL_PREFIX), 'Citrix OpenStack VPX') geppetto_roles = [ Role.get_by_name(Role.CELERY_WORKER), Role.get_by_name(Role.CELERY_CAMERA) ] if kwargs['vpx_master_db_host'] in [master_hostname, 'localhost']: geppetto_roles.append(Role.get_by_name(Role.MYSQL)) if kwargs['vpx_master_queue_host'] in [master_hostname, 'localhost']: geppetto_roles.append(Role.get_by_name(Role.RABBITMQ)) roles_to_apply = [r for r in geppetto_roles \ if not NodeRoleAssignment.exists(master, r)] NodeRoleAssignment.add_roles_to_node(master, roles_to_apply, True)
def assign_and_configure_roles_to_node(node_fqdn, role_list, node_config=None): node = Node.get_by_name(node_fqdn) if node_config != None: for param_label, value in node_config.iteritems(): param = ConfigClassParameter.get_by_name(param_label) Override.update_or_create_override(node, param, value) roles = [Role.get_by_name(role_name) for role_name in role_list] NodeRoleAssignment.add_roles_to_node(node, roles, True)
def test_copy_node_overrides(self): node_src = self._add_dummy_node('node_src') node_dst = self._add_dummy_node('node_dst') c1 = config.get_by_name('HAPI_PASS') c2 = config.get_by_name('HAPI_USER') overrides = \ [Override.\ objects.create(node=node_src, config_class_parameter=c1, value='mysecret'), Override.\ objects.create(node=node_src, config_class_parameter=c2, value='myuser'), ] Override.copy_node_overrides(node_dst, overrides) self.assertDictEqual(node_dst.get_overrides_dict(), node_src.get_overrides_dict())
def _add_dummy_override(self, fqdn='test_fqdn', config="VPX_DESCRIPTION", value="test"): self._add_dummy_node(fqdn) node = self._get_dummy_node() config_class_parameter = ConfigClassParameter.get_by_name(config) Override.objects.create(node=node, config_class_parameter=config_class_parameter, value=value)
def test_Compute___add_message_queue_valid_params_returns_task_id(self): self._add_dummy_node('test1') result = self.svc.Compute___add_message_queue("test1") self.assertEqual(result, "task_id") dummy_node = self._get_dummy_node() role_list = dummy_node.get_roles() self.assertEqual([Role.get_by_name("rabbitmq-server")], role_list) rabbit_host = ConfigClassParameter.get_by_name("RABBIT_HOST") self.assertEqual("test1", rabbit_host.default_value)
def test_get_overrides(self): node = self._add_blank_node() d1 = {config.HAPI_USER: '******', config.HAPI_PASS: '******', config.MYSQL_USER: '******', config.MYSQL_PASS: '******', } for key, value in d1.iteritems(): Override.update_or_create_override(node, config.get_by_name(key), value) d2 = node.get_overrides_dict() self.assertDictEqual(d1, d2)
def model_reset(): """Recover the database to a pristine state""" Node.objects.all().delete() master = Master.get_infrastructure_master() master.fqdn = 'master' master.promoted_date = datetime.datetime(2001, 1, 1, 0, 0, 0, 0) master.save() root = User.objects.get(username='******') root.last_login = datetime.datetime(2001, 1, 1, 0, 0, 0, 0) root.save() config = ConfigClassParameter.get_by_name(ConfigClassParameter.\ VPX_LOGGING_COLLECTOR) config.default_value = 'localhost' config.save()
def test_BlockStorage___add_workers_valid_parms_returns_task_id(self): self._add_dummy_node('test1') result = self.svc.BlockStorage___add_workers(["test1"], { "TYPE": "iscsi", "VOLUME_DISK_SIZE_GB": "5" }) self.assertEqual(result, "task_id") dummy_node = self._get_dummy_node() role_list = dummy_node.get_roles() self.assertEqual([Role.get_by_name("openstack-nova-volume")], role_list) volume_driver = ConfigClassParameter.get_by_name("VOLUME_DRIVER") self.assertEqual("nova.volume.driver.ISCSIDriver", volume_driver.default_value) use_local_volumes = ConfigClassParameter.\ get_by_name("USE_LOCAL_VOLUMES") self.assertEqual("True", use_local_volumes.default_value) size = ConfigClassParameter.get_by_name("VOLUME_DISK_SIZE_GB") self.assertEqual("5", size.default_value)
def get_or_create_node(node_fqdn): try: node = Node.get_by_name(node_fqdn) except: node = Node.create(node_fqdn) # Generate and assign a Host GUID host_guid = _generate_host_guid() param = ConfigClassParameter.get_by_name( ConfigClassParameter.HOST_GUID) Override.update_or_create_override(node, param, host_guid) # Assign default roles on node creation default_roles = Role.get_default_roles() NodeRoleAssignment.add_roles_to_node(node, default_roles) # determine if we can add celeryd on each worker. This is # possible only if the DB backend is != sqlite3 if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql': celery_role = Role.get_by_name(Role.CELERY_WORKER) NodeRoleAssignment.add_roles_to_node(node, [celery_role], True) return node
def test_BlockStorage___add_workers_valid_parms_returns_task_id_sm(self): self._add_dummy_node('test1') result = self.svc.BlockStorage___add_workers(["test1"], {"TYPE": "xenserver_sm"}) self.assertEqual(result, "task_id") dummy_node = self._get_dummy_node() role_list = dummy_node.get_roles() self.assertEqual([Role.get_by_name("openstack-nova-volume")], role_list) volume_driver = ConfigClassParameter.get_by_name("VOLUME_DRIVER") self.assertEqual("nova.volume.xensm.XenSMDriver", volume_driver.default_value) use_local_volumes = ConfigClassParameter.\ get_by_name("USE_LOCAL_VOLUMES") self.assertEqual("False", use_local_volumes.default_value)
def create_swift_rings(hostnames): """This attempts to create the swift ring file on the master, given the specified hostnames of the swift object nodes.""" # Resolve IPs # TODO - we should have this info in the facts ips = [] for hostname in hostnames: ips.append(socket.gethostbyname(hostname)) ips_str = string.join(ips, " ") # Assign Ring Builder Role: runs on this host node_fqdn = network.get_hostname() node = Node.get_by_name(node_fqdn) Override.update_or_create_override( node, ConfigClassParameter.get_by_name(ConfigClassParameter.SWIFT_NODES_IPS), ips_str) NodeRoleAssignment.add_roles_to_node(node, [Role.get_by_name(Role.RING_BUILDER)], True) return node_fqdn
def _add_dummy_node(self, fqdn='test_fqdn', is_enabled=True): self.dummy_node_fqdn = fqdn node = Node.create(fqdn) node.enabled = is_enabled import pickle node.facts = pickle.dumps({ "geppetto_status_running_services": "openstack-nova-api,openstack-nova-compute", "geppetto_status_stopped_services": "openstack-nova-network", "host_fqdn": "test_host", "ipaddress_eth0": "169.254.0.2", "ipaddress_eth1": "127.0.0.1", "interfaces": "'eth0,eth1,eth2,lo'", }) node.save() node.joined_date = datetime.datetime(2001, 1, 1, 0, 0, 0, 0) # make the host guid predictable param = ConfigClassParameter.get_by_name( ConfigClassParameter.HOST_GUID) Override.update_or_create_override(node, param, "00:00:00:00:00:00") return node