def test_installation_info(self): info = InstallationInfo() nodes_params = [{ 'roles': ['compute'] }, { 'roles': ['compute'] }, { 'roles': ['controller'] }] self.env.create( release_kwargs={'operating_system': consts.RELEASE_OS.centos}, cluster_kwargs={}, nodes_kwargs=nodes_params) unallocated_nodes_params = [{ 'status': consts.NODE_STATUSES.discover }, { 'status': consts.NODE_STATUSES.discover }] for unallocated_node in unallocated_nodes_params: self.env.create_node(**unallocated_node) info = info.get_installation_info() self.assertEquals(1, info['clusters_num']) self.assertEquals(len(nodes_params), info['allocated_nodes_num']) self.assertEquals(len(unallocated_nodes_params), info['unallocated_nodes_num']) self.assertTrue('master_node_uid' in info) self.assertTrue('contact_info_provided' in info['user_information']) self.assertDictEqual(settings.VERSION, info['fuel_release'])
def test_get_attributes_exception_handled(self): info = InstallationInfo() variants = [ None, [], {}, { 'common': None }, { 'common': [] }, { 'common': { 'libvirt_type': {} } }, { 'common': { 'libvirt_type': 3 } }, ] for attrs in variants: result = info.get_attributes(attrs) self.assertDictEqual({}, result)
def test_installation_info(self): info = InstallationInfo() nodes_params = [ {'roles': ['compute']}, {'roles': ['compute']}, {'roles': ['controller']} ] self.env.create( release_kwargs={ 'operating_system': consts.RELEASE_OS.centos }, cluster_kwargs={}, nodes_kwargs=nodes_params ) unallocated_nodes_params = [ {'status': consts.NODE_STATUSES.discover}, {'status': consts.NODE_STATUSES.discover} ] for unallocated_node in unallocated_nodes_params: self.env.create_node(**unallocated_node) info = info.get_installation_info() self.assertEquals(1, info['clusters_num']) self.assertEquals(len(nodes_params), info['allocated_nodes_num']) self.assertEquals(len(unallocated_nodes_params), info['unallocated_nodes_num']) self.assertTrue('master_node_uid' in info) self.assertDictEqual(settings.VERSION, info['fuel_release'])
def test_clusters_info(self): self.env.upload_fixtures(['openstack']) info = InstallationInfo() release = ReleaseCollection.filter_by(None, operating_system='CentOS') nodes_params = [ {'roles': ['compute']}, {'roles': ['compute']}, {'roles': ['controller']} ] self.env.create( cluster_kwargs={ 'release_id': release[0].id, 'mode': consts.CLUSTER_MODES.ha_full, 'net_provider': consts.CLUSTER_NET_PROVIDERS.nova_network}, nodes_kwargs=nodes_params ) self.env.create_node({'status': consts.NODE_STATUSES.discover}) clusters_info = info.get_clusters_info() cluster = self.env.clusters[0] self.assertEquals(1, len(clusters_info)) cluster_info = clusters_info[0] self.assertEquals(len(nodes_params), len(cluster_info['nodes'])) self.assertEquals(len(nodes_params), cluster_info['nodes_num']) self.assertEquals(consts.CLUSTER_MODES.ha_full, cluster_info['mode']) self.assertEquals(consts.CLUSTER_NET_PROVIDERS.nova_network, cluster_info['net_provider']) self.assertEquals(consts.CLUSTER_STATUSES.new, cluster_info['status']) self.assertEquals(False, cluster_info['is_customized']) self.assertEquals(cluster.id, cluster_info['id']) self.assertEquals(cluster.fuel_version, cluster_info['fuel_version']) self.assertTrue('attributes' in cluster_info) self.assertTrue('release' in cluster_info) self.assertEquals(cluster.release.operating_system, cluster_info['release']['os']) self.assertEquals(cluster.release.name, cluster_info['release']['name']) self.assertEquals(cluster.release.version, cluster_info['release']['version']) self.assertEquals(1, len(cluster_info['node_groups'])) group_info = cluster_info['node_groups'][0] group = [ng for ng in cluster.node_groups][0] self.assertEquals(group.id, group_info['id']) self.assertEquals(len(nodes_params), len(group_info['nodes'])) self.assertEquals(set([n.id for n in group.nodes]), set(group_info['nodes']))
def test_get_attributes_centos(self): self.env.upload_fixtures(['openstack']) info = InstallationInfo() release = ReleaseCollection.filter_by(None, operating_system='CentOS') cluster_data = self.env.create_cluster(release_id=release[0].id) cluster = Cluster.get_by_uid(cluster_data['id']) editable = cluster.attributes.editable attr_key_list = [a[1] for a in info.attributes_white_list] attrs_dict = info.get_attributes(editable) self.assertEqual(set(attr_key_list), set(attrs_dict.keys()))
def test_installation_info_when_stats_info_deleted(self): settings_from_db = objects.MasterNodeSettings.get_one() self.db.delete(settings_from_db) self.db.commit() self.assertDictEqual( InstallationInfo().get_installation_info()['user_information'], {'contact_info_provided': False}) self.assertIsNone( InstallationInfo().get_installation_info()['master_node_uid'])
def test_clusters_info(self): self.env.upload_fixtures(['openstack']) info = InstallationInfo() release = ReleaseCollection.filter_by(None, operating_system='CentOS') nodes_params = [{ 'roles': ['compute'] }, { 'roles': ['compute'] }, { 'roles': ['controller'] }] self.env.create(cluster_kwargs={ 'release_id': release[0].id, 'mode': consts.CLUSTER_MODES.ha_full, 'net_provider': consts.CLUSTER_NET_PROVIDERS.nova_network }, nodes_kwargs=nodes_params) self.env.create_node({'status': consts.NODE_STATUSES.discover}) clusters_info = info.get_clusters_info() cluster = self.env.clusters[0] self.assertEquals(1, len(clusters_info)) cluster_info = clusters_info[0] self.assertEquals(len(nodes_params), len(cluster_info['nodes'])) self.assertEquals(len(nodes_params), cluster_info['nodes_num']) self.assertEquals(consts.CLUSTER_MODES.ha_full, cluster_info['mode']) self.assertEquals(consts.CLUSTER_NET_PROVIDERS.nova_network, cluster_info['net_provider']) self.assertEquals(consts.CLUSTER_STATUSES.new, cluster_info['status']) self.assertEquals(False, cluster_info['is_customized']) self.assertEquals(cluster.id, cluster_info['id']) self.assertEquals(cluster.fuel_version, cluster_info['fuel_version']) self.assertTrue('attributes' in cluster_info) self.assertTrue('release' in cluster_info) self.assertEquals(cluster.release.operating_system, cluster_info['release']['os']) self.assertEquals(cluster.release.name, cluster_info['release']['name']) self.assertEquals(cluster.release.version, cluster_info['release']['version']) self.assertEquals(1, len(cluster_info['node_groups'])) group_info = cluster_info['node_groups'][0] group = [ng for ng in cluster.node_groups][0] self.assertEquals(group.id, group_info['id']) self.assertEquals(len(nodes_params), len(group_info['nodes'])) self.assertEquals(set([n.id for n in group.nodes]), set(group_info['nodes']))
def test_get_attributes_ubuntu(self): self.env.upload_fixtures(['openstack']) info = InstallationInfo() release = ReleaseCollection.filter_by(None, operating_system='Ubuntu') cluster_data = self.env.create_cluster(release_id=release[0].id) cluster = Cluster.get_by_uid(cluster_data['id']) editable = cluster.attributes.editable attr_key_list = [a[1] for a in info.attributes_white_list] attrs_dict = info.get_attributes(editable) self.assertEqual( # no vlan splinters for ubuntu set(attr_key_list) - set(('vlan_splinters', 'vlan_splinters_ovs')), set(attrs_dict.keys()))
def test_get_attributes_exception_handled(self): info = InstallationInfo() variants = [ None, [], {}, {'common': None}, {'common': []}, {'common': {'libvirt_type': {}}}, {'common': {'libvirt_type': 3}}, ] for attrs in variants: result = info.get_attributes(attrs) self.assertDictEqual({}, result)
def test_get_attributes_centos(self): self.env.upload_fixtures(['openstack']) info = InstallationInfo() release = ReleaseCollection.filter_by(None, operating_system='CentOS') cluster_data = self.env.create_cluster( release_id=release[0].id ) cluster = Cluster.get_by_uid(cluster_data['id']) editable = cluster.attributes.editable attr_key_list = [a[1] for a in info.attributes_white_list] attrs_dict = info.get_attributes(editable) self.assertEqual( set(attr_key_list), set(attrs_dict.keys()) )
def test_get_attributes_ubuntu(self): self.env.upload_fixtures(['openstack']) info = InstallationInfo() release = ReleaseCollection.filter_by(None, operating_system='Ubuntu') cluster_data = self.env.create_cluster( release_id=release[0].id ) cluster = Cluster.get_by_uid(cluster_data['id']) editable = cluster.attributes.editable attr_key_list = [a[1] for a in info.attributes_white_list] attrs_dict = info.get_attributes(editable) self.assertEqual( # no vlan splinters for ubuntu set(attr_key_list) - set(('vlan_splinters', 'vlan_splinters_ovs')), set(attrs_dict.keys()) )
def send_oswl_info(self): logger.info("Sending OpenStack workload info") oswl_data = objects.OpenStackWorkloadStatsCollection\ .get_ready_to_send().limit(settings.OSWL_SEND_COUNT) logger.info("Pending records count: %s", six.text_type(oswl_data.count())) uid = InstallationInfo().get_master_node_uid() offset = 0 records = [] ids = [] while True: data_chunk = oswl_data.offset(offset) for rec in data_chunk: rec_data = objects.OpenStackWorkloadStats.to_dict(rec) rec_data['master_node_uid'] = uid rec_data['created_date'] = rec_data['created_date'].isoformat() rec_data['updated_time'] = rec_data['updated_time'].isoformat() records.append(rec_data) ids.append(rec_data['id']) self.send_oswl_serialized(records, ids) if data_chunk.count() < settings.OSWL_SEND_COUNT: break offset += settings.OSWL_SEND_COUNT logger.info("OpenStack workload info is sent")
def send_action_log(self): action_log = db().query(models.ActionLog).order_by( models.ActionLog.id).filter_by(is_sent=False).limit( settings.STATS_SEND_COUNT) logger.info("Action log has %d unsent records", action_log.count()) uid = InstallationInfo().get_master_node_uid() offset = 0 while True: log_chunk = action_log.offset(offset) records = [] ids = [] logger.info("Send records: %s", six.text_type(log_chunk.count())) for log_record in log_chunk: body = objects.ActionLog.to_dict(log_record) record = { 'external_id': body['id'], 'master_node_uid': uid, 'body': body } records.append(record) ids.append(log_record.id) self.send_log_serialized(records, ids) if log_chunk.count() < settings.STATS_SEND_COUNT: break offset += settings.STATS_SEND_COUNT
def test_partial_user_contacts_info(self): resp = self.app.get( reverse("MasterNodeSettingsHandler"), headers=self.default_headers) self.assertEqual(200, resp.status_code) data = resp.json_body # emulate user enabled contact info sending to support team data["settings"]["statistics"]["user_choice_saved"]["value"] = True data["settings"]["statistics"]["send_user_info"]["value"] = \ True name = "user" email = "*****@*****.**" data["settings"]["statistics"]["name"]["value"] = name data["settings"]["statistics"]["email"]["value"] = email resp = self.app.put( reverse("MasterNodeSettingsHandler"), headers=self.default_headers, params=jsonutils.dumps(data) ) self.assertEqual(200, resp.status_code) self.assertDictEqual( InstallationInfo().get_installation_info()['user_information'], { 'contact_info_provided': True, 'name': name, 'email': email, 'company': '' } )
def test_nodes_info(self): info = InstallationInfo() self.env.create( release_kwargs={ 'operating_system': consts.RELEASE_OS.centos }, nodes_kwargs=[ {'status': consts.NODE_STATUSES.ready, 'roles': ['controller', 'compute']}, {'roles': [], 'pending_roles': ['compute']} ] ) self.env.make_bond_via_api( 'bond0', consts.OVS_BOND_MODES.active_backup, ['eth0', 'eth1'], node_id=self.env.nodes[0].id) nodes_info = info.get_nodes_info(self.env.nodes) self.assertEquals(len(self.env.nodes), len(nodes_info)) for idx, node in enumerate(self.env.nodes): node_info = nodes_info[idx] self.assertEquals(node_info['id'], node.id) self.assertEquals(node_info['group_id'], node.group_id) self.assertListEqual(node_info['roles'], node.roles) self.assertEquals(node_info['os'], node.os_platform) self.assertEquals(node_info['status'], node.status) self.assertEquals(node_info['error_type'], node.error_type) self.assertEquals(node_info['online'], node.online) self.assertEquals(node_info['manufacturer'], node.manufacturer) self.assertEquals(node_info['platform_name'], node.platform_name) self.assertEquals(node_info['pending_addition'], node.pending_addition) self.assertEquals(node_info['pending_deletion'], node.pending_deletion) self.assertEquals(node_info['pending_roles'], node.pending_roles) self.assertEqual( node_info['nic_interfaces'], [{'id': i.id} for i in node.nic_interfaces] ) self.assertEqual( node_info['bond_interfaces'], [{'id': i.id, 'slaves': [s.id for s in i.slaves]} for i in node.bond_interfaces] )
def test_nodes_info(self): info = InstallationInfo() self.env.create( release_kwargs={'operating_system': consts.RELEASE_OS.centos}, nodes_kwargs=[{ 'status': consts.NODE_STATUSES.ready, 'roles': ['controller', 'compute'] }, { 'roles': [], 'pending_roles': ['compute'] }]) self.env.make_bond_via_api('bond0', consts.OVS_BOND_MODES.active_backup, ['eth0', 'eth1'], node_id=self.env.nodes[0].id) nodes_info = info.get_nodes_info(self.env.nodes) self.assertEquals(len(self.env.nodes), len(nodes_info)) for idx, node in enumerate(self.env.nodes): node_info = nodes_info[idx] self.assertEquals(node_info['id'], node.id) self.assertEquals(node_info['group_id'], node.group_id) self.assertListEqual(node_info['roles'], node.roles) self.assertEquals(node_info['os'], node.os_platform) self.assertEquals(node_info['status'], node.status) self.assertEquals(node_info['error_type'], node.error_type) self.assertEquals(node_info['online'], node.online) self.assertEquals(node_info['manufacturer'], node.manufacturer) self.assertEquals(node_info['platform_name'], node.platform_name) self.assertEquals(node_info['pending_addition'], node.pending_addition) self.assertEquals(node_info['pending_deletion'], node.pending_deletion) self.assertEquals(node_info['pending_roles'], node.pending_roles) self.assertEqual(node_info['nic_interfaces'], [{ 'id': i.id } for i in node.nic_interfaces]) self.assertEqual(node_info['bond_interfaces'], [{ 'id': i.id, 'slaves': [s.id for s in i.slaves] } for i in node.bond_interfaces])
def test_user_contacts_info_broken(self): settings_from_db = objects.MasterNodeSettings.get_one() settings = dict(settings_from_db.settings) settings["statistics"] = None settings_from_db.settings = settings self.db.commit() self.assertDictEqual( InstallationInfo().get_installation_info()['user_information'], {'contact_info_provided': False})
def test_nodes_info(self): info = InstallationInfo() self.env.create( release_kwargs={ 'operating_system': consts.RELEASE_OS.centos }, nodes_kwargs=[ {'status': consts.NODE_STATUSES.ready, 'roles': ['controller', 'compute']}, {'roles': []} ] ) nodes_info = info.get_nodes_info(self.env.nodes) self.assertEquals(len(self.env.nodes), len(nodes_info)) for idx, node in enumerate(self.env.nodes): node_info = nodes_info[idx] self.assertEquals(node_info['id'], node.id) self.assertEquals(node_info['status'], node.status) self.assertListEqual(node_info['roles'], node.roles) self.assertEquals(node_info['os'], node.os_platform)
def send_installation_info(self): logger.info("Sending installation structure info") inst_info = InstallationInfo().get_installation_info() resp = self.send_data_to_url( url=self.build_collector_url("COLLECTOR_INST_INFO_URL"), data={"installation_structure": inst_info}) resp_dict = resp.json() if self.is_status_acceptable(resp.status_code, resp_dict["status"]): logger.info("Installation structure info saved in collector") else: logger.error("Unexpected collector answer: %s", six.text_type(resp.text))
def test_clusters_info(self): info = InstallationInfo() nodes_params = [ {'roles': ['compute']}, {'roles': ['compute']}, {'roles': ['controller']} ] self.env.create( release_kwargs={ 'operating_system': consts.RELEASE_OS.centos }, cluster_kwargs={'mode': consts.CLUSTER_MODES.ha_full}, nodes_kwargs=nodes_params ) self.env.create_node({'status': consts.NODE_STATUSES.discover}) clusters_info = info.get_clusters_info() self.assertEquals(1, len(clusters_info)) cluster_info = clusters_info[0] self.assertEquals(len(nodes_params), len(cluster_info['nodes'])) self.assertEquals(len(nodes_params), cluster_info['nodes_num']) self.assertEquals(consts.CLUSTER_MODES.ha_full, cluster_info['mode']) self.assertTrue('release' in cluster_info) self.assertEquals(consts.RELEASE_OS.centos, cluster_info['release']['os'])
def test_user_contacts_info_disabled_by_default(self): resp = self.app.get( reverse("MasterNodeSettingsHandler"), headers=self.default_headers) self.assertEqual(200, resp.status_code) data = resp.json_body # emulate user confirmed settings in UI data["settings"]["statistics"]["user_choice_saved"]["value"] = True resp = self.app.put( reverse("MasterNodeSettingsHandler"), headers=self.default_headers, params=jsonutils.dumps(data) ) self.assertEqual(200, resp.status_code) self.assertDictEqual( InstallationInfo().get_installation_info()['user_information'], {'contact_info_provided': False})
def test_user_contacts_info_disabled_while_not_confirmed_by_user(self): self.assertDictEqual( InstallationInfo().get_installation_info()['user_information'], {'contact_info_provided': False})
def test_release_info(self): info = InstallationInfo() f_info = info.fuel_release_info() self.assertDictEqual(f_info, settings.VERSION)
def test_get_empty_attributes(self): info = InstallationInfo() trash_attrs = {'some': 'trash', 'nested': {'n': 't'}} result = info.get_attributes(trash_attrs) self.assertDictEqual({}, result)