def test_nodes_info(self):
        info = InstallationInfo()
        cluster = self.env.create(
            release_kwargs={
                'operating_system': consts.RELEASE_OS.centos
            })
        self.env.create_nodes_w_interfaces_count(
            nodes_count=2,
            if_count=4,
            roles=['controller', 'compute'],
            pending_addition=True,
            cluster_id=cluster['id'])

        self.env.make_bond_via_api(
            'bond0', consts.BOND_MODES.active_backup,
            ['eth1', 'eth2'], node_id=self.env.nodes[0].id,
            attrs={'type__': {'value': consts.BOND_TYPES.linux}})
        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.assertIn('meta', node_info)
            for iface in node_info['meta']['interfaces']:
                self.assertNotIn('mac', iface)
            self.assertNotIn('fqdn', node_info['meta']['system'])
            self.assertNotIn('serial', node_info['meta']['system'])
            self.assertIn('cpu', node_info['meta'])
            self.assertIn('memory', node_info['meta'])
            self.assertIn('disks', node_info['meta'])
            self.assertIn('pci_devices', node_info['meta'])
            self.assertIn('interfaces', node_info['meta'])
            self.assertIn('numa_topology', node_info['meta'])

            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_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_nodes_info(self):
        info = InstallationInfo()
        cluster = self.env.create(
            release_kwargs={'operating_system': consts.RELEASE_OS.centos})
        self.env.create_nodes_w_interfaces_count(
            nodes_count=2,
            if_count=4,
            roles=['controller', 'compute'],
            pending_addition=True,
            cluster_id=cluster['id'])

        self.env.make_bond_via_api(
            'bond0',
            consts.BOND_MODES.active_backup, ['eth1', 'eth2'],
            node_id=self.env.nodes[0].id,
            attrs={'type__': {
                'value': consts.BOND_TYPES.linux
            }})
        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.assertIn('meta', node_info)
            for iface in node_info['meta']['interfaces']:
                self.assertNotIn('mac', iface)
            self.assertNotIn('fqdn', node_info['meta']['system'])
            self.assertNotIn('serial', node_info['meta']['system'])
            self.assertIn('cpu', node_info['meta'])
            self.assertIn('memory', node_info['meta'])
            self.assertIn('disks', node_info['meta'])
            self.assertIn('pci_devices', node_info['meta'])
            self.assertIn('interfaces', node_info['meta'])
            self.assertIn('numa_topology', node_info['meta'])

            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_network_configuration(self):
        info = InstallationInfo()
        # Checking nova network configuration
        nova = consts.CLUSTER_NET_PROVIDERS.nova_network
        self.env.create(cluster_kwargs={
            'mode': consts.CLUSTER_MODES.ha_compact,
            'net_provider': nova
        })
        clusters_info = info.get_clusters_info()
        cluster_info = clusters_info[0]
        self.assertTrue('network_configuration' in cluster_info)
        network_config = cluster_info['network_configuration']

        for field in ('fixed_network_size', 'fixed_networks_vlan_start',
                      'fixed_networks_amount', 'net_manager'):
            self.assertIn(field, network_config)

        # Checking neutron network configuration
        neutron = consts.CLUSTER_NET_PROVIDERS.neutron
        self.env.create(cluster_kwargs={
            'mode': consts.CLUSTER_MODES.ha_compact,
            'net_provider': neutron
        })
        clusters_info = info.get_clusters_info()
        # Clusters info is unordered list, so we should find required
        # cluster_info
        cluster_info = filter(lambda x: x['net_provider'] == neutron,
                              clusters_info)[0]
        self.assertTrue('network_configuration' in cluster_info)
        network_config = cluster_info['network_configuration']

        for field in ('segmentation_type', 'net_l23_provider'):
            self.assertIn(field, network_config)
 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_network_configuration(self):
        info = InstallationInfo()
        # Checking nova network configuration
        nova = consts.CLUSTER_NET_PROVIDERS.nova_network
        self.env.create(cluster_kwargs={"mode": consts.CLUSTER_MODES.ha_compact, "net_provider": nova})
        clusters_info = info.get_clusters_info()
        cluster_info = clusters_info[0]
        self.assertTrue("network_configuration" in cluster_info)
        network_config = cluster_info["network_configuration"]

        for field in ("fixed_network_size", "fixed_networks_vlan_start", "fixed_networks_amount", "net_manager"):
            self.assertIn(field, network_config)

        # Checking neutron network configuration
        neutron = consts.CLUSTER_NET_PROVIDERS.neutron
        self.env.create(cluster_kwargs={"mode": consts.CLUSTER_MODES.ha_compact, "net_provider": neutron})
        clusters_info = info.get_clusters_info()
        # Clusters info is unordered list, so we should find required
        # cluster_info
        cluster_info = filter(lambda x: x["net_provider"] == neutron, clusters_info)[0]
        self.assertTrue("network_configuration" in cluster_info)
        network_config = cluster_info["network_configuration"]

        for field in ("segmentation_type", "net_l23_provider"):
            self.assertIn(field, network_config)
    def test_plugins_info(self):
        info = InstallationInfo()

        cluster = self.env.create_cluster(api=False)

        plugin_kwargs = self.env.get_default_plugin_metadata()
        plugin_obj = plugins.Plugin(**plugin_kwargs)

        self.db.add(plugin_obj)
        self.db.flush()

        plugin_kwargs["id"] = plugin_obj.id

        cluster_plugin_kwargs = {"cluster_id": cluster.id, "plugin_id": plugin_obj.id, "enabled": True}
        cluster_plugin = plugins.ClusterPlugins(**cluster_plugin_kwargs)

        self.db.add(cluster_plugin)
        self.db.flush()

        expected_attributes_names = ("id", "name", "version", "releases", "fuel_version", "package_version")

        expected_info = dict(
            [(key, value) for key, value in six.iteritems(plugin_kwargs) if key in expected_attributes_names]
        )

        expected = [expected_info]
        actual = info.get_cluster_plugins_info(cluster)
        self.assertEqual(expected, actual)
    def test_network_configuration(self):
        info = InstallationInfo()
        # Checking nova network configuration
        nova = consts.CLUSTER_NET_PROVIDERS.nova_network
        self.env.create(cluster_kwargs={
            'mode': consts.CLUSTER_MODES.ha_full,
            'net_provider': nova
        })
        clusters_info = info.get_clusters_info()
        cluster_info = clusters_info[0]
        self.assertTrue('network_configuration' in cluster_info)
        network_config = cluster_info['network_configuration']

        for field in ('fixed_network_size', 'fixed_networks_vlan_start',
                      'fixed_networks_amount', 'net_manager'):
            self.assertIn(field, network_config)

        # Checking neutron network configuration
        neutron = consts.CLUSTER_NET_PROVIDERS.neutron
        self.env.create(cluster_kwargs={
            'mode': consts.CLUSTER_MODES.ha_full,
            'net_provider': neutron
        })
        clusters_info = info.get_clusters_info()
        # Clusters info is unordered list, so we should find required
        # cluster_info
        cluster_info = filter(lambda x: x['net_provider'] == neutron,
                              clusters_info)[0]
        self.assertTrue('network_configuration' in cluster_info)
        network_config = cluster_info['network_configuration']

        for field in ('segmentation_type', 'net_l23_provider'):
            self.assertIn(field, network_config)
    def test_all_cluster_data_collected(self):
        self.env.create(nodes_kwargs=[{'roles': ['compute']}])
        self.env.create_node(status=consts.NODE_STATUSES.discover)

        # Fetching installation info struct
        info = InstallationInfo()
        info = info.get_installation_info()
        actual_cluster = info['clusters'][0]

        cluster_schema = self.get_model_schema(models.Cluster)

        # Removing of not required fields
        remove_fields = ('tasks', 'cluster_changes', 'nodegroups', 'releases',
                         'replaced_provisioning_info', 'notifications',
                         'cluster_deployment_graphs', 'name',
                         'replaced_deployment_info', 'ui_settings')
        for field in remove_fields:
            cluster_schema.pop(field)
        # Renaming fields for matching
        rename_fields = (
            ('plugins', 'installed_plugins'),
            ('networking_configs', 'network_configuration'),
            ('release_id', 'release'),
            ('cluster_plugin_links', 'plugin_links'),
        )
        for name_from, name_to in rename_fields:
            cluster_schema.pop(name_from)
            cluster_schema[name_to] = None

        # If test failed here it means, that you have added properties
        # to cluster and they are not exported into statistics.
        # If you don't know  what to do, contact fuel-stats team please.
        for key in six.iterkeys(cluster_schema):
            self.assertIn(key, actual_cluster)
    def test_clusters_info(self):
        self.env.upload_fixtures(['openstack'])
        info = InstallationInfo()
        release = ReleaseCollection.filter_by(
            None, operating_system=consts.RELEASE_OS.ubuntu)
        nodes_params = [
            {'roles': ['compute']},
            {'roles': ['compute']},
            {'roles': ['controller']}
        ]
        cluster = self.env.create(
            cluster_kwargs={
                'release_id': release[0].id,
                'mode': consts.CLUSTER_MODES.ha_compact,
                'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron},
            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_compact,
                          cluster_info['mode'])
        self.assertEquals(consts.CLUSTER_NET_PROVIDERS.neutron,
                          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_clusters_info(self):
        self.env.upload_fixtures(['openstack'])
        info = InstallationInfo()
        release = ReleaseCollection.filter_by(
            None, operating_system=consts.RELEASE_OS.ubuntu)
        nodes_params = [
            {'roles': ['compute']},
            {'roles': ['compute']},
            {'roles': ['controller']}
        ]
        cluster = self.env.create(
            cluster_kwargs={
                'release_id': release[0].id,
                'mode': consts.CLUSTER_MODES.ha_compact,
                'net_provider': consts.CLUSTER_NET_PROVIDERS.neutron},
            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_compact,
                          cluster_info['mode'])
        self.assertEquals(consts.CLUSTER_NET_PROVIDERS.neutron,
                          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_nodes_info(self):
        info = InstallationInfo()
        self.env.create(
            release_kwargs={
                'operating_system': consts.RELEASE_OS.centos
            },
            nodes_kwargs=[
                {'status': consts.NODE_STATUSES.discover,
                 'roles': ['controller', 'compute'],
                 'meta': {}},
                {'roles': [],
                 'pending_roles': ['compute'],
                 'meta': {'cpu': {},
                          'interfaces': [{'mac': 'x', 'name': 'eth0'}],
                          'disks': [{'name': 'a', 'disk': 'a'}]}}
            ]
        )
        self.env.make_bond_via_api(
            'bond0', consts.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.assertIn('meta', node_info)
            for iface in node_info['meta']['interfaces']:
                self.assertNotIn('mac', iface)
            self.assertNotIn('fqdn', node_info['meta']['system'])
            self.assertNotIn('serial', node_info['meta']['system'])

            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]
            )
Beispiel #13
0
 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, info.attributes_white_list)
     self.assertEqual(set(attr_key_list), set(attrs_dict.keys()))
Beispiel #14
0
    def _do_test_attributes_in_white_list(self, release, expected_attributes):
        cluster_data = self.env.create_cluster(release_id=release.id)
        cluster = Cluster.get_by_uid(cluster_data['id'])
        editable = cluster.attributes.editable

        info = InstallationInfo()
        actual_attributes = info.get_attributes(editable,
                                                info.attributes_white_list)
        self.assertEqual(set(expected_attributes),
                         set(actual_attributes.keys()))
Beispiel #15
0
    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_get_attributes_centos(self):
     self.skipTest("CentOS is unavailable in current release.")
     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, info.attributes_white_list)
     self.assertEqual(set(attr_key_list), set(attrs_dict.keys()))
 def test_get_attributes_exception_handled(self):
     info = InstallationInfo()
     variants = [
         None,
         {},
         {'common': None},
         {'common': {'libvirt_type': {}}},
         {'common': {'libvirt_type': 3}},
     ]
     for attrs in variants:
         result = info.get_attributes(attrs, info.attributes_white_list)
         self.assertDictEqual({}, result)
 def test_get_attributes_exception_handled(self):
     info = InstallationInfo()
     variants = [
         None,
         {},
         {'common': None},
         {'common': {'libvirt_type': {}}},
         {'common': {'libvirt_type': 3}},
     ]
     for attrs in variants:
         result = info.get_attributes(attrs, info.attributes_white_list)
         self.assertDictEqual({}, result)
Beispiel #19
0
 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, info.attributes_white_list)
     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_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, info.attributes_white_list)
     self.assertEqual(
         # no vlan splinters for ubuntu
         set(attr_key_list) - set(("vlan_splinters", "vlan_splinters_ovs")),
         set(attrs_dict.keys()),
     )
    def _do_test_attributes_in_white_list(self, release,
                                          expected_attributes):
        cluster_data = self.env.create_cluster(
            release_id=release.id
        )
        cluster = Cluster.get_by_uid(cluster_data['id'])
        editable = cluster.attributes.editable

        info = InstallationInfo()
        actual_attributes = info.get_attributes(
            editable, info.attributes_white_list)
        self.assertEqual(
            set(expected_attributes),
            set(actual_attributes.keys())
        )
Beispiel #22
0
    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
Beispiel #23
0
    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 test_unicode_master_node_settings(self):
        data = self.get_current_settings()

        # 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 = u"Фёдор Я"
        email = "*****@*****.**"
        company = u"Компания"
        data["settings"]["statistics"]["name"]["value"] = name
        data["settings"]["statistics"]["email"]["value"] = email
        data["settings"]["statistics"]["company"]["value"] = company
        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': company
            })
Beispiel #25
0
    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': ''
            })
Beispiel #26
0
 def test_clusters_info_no_vmware_attributes_exception(self):
     self.env.upload_fixtures(['openstack'])
     info = InstallationInfo()
     release = ReleaseCollection.filter_by(
         None, operating_system=consts.RELEASE_OS.ubuntu)
     nodes_params = [{
         'roles': ['compute']
     }, {
         'roles': ['compute']
     }, {
         'roles': ['controller']
     }]
     cluster = self.env.create(cluster_kwargs={
         'release_id':
         release[0].id,
         'mode':
         consts.CLUSTER_MODES.ha_compact,
         'net_provider':
         consts.CLUSTER_NET_PROVIDERS.neutron
     },
                               nodes_kwargs=nodes_params)
     self.env.create_node({'status': consts.NODE_STATUSES.discover})
     VmwareAttributes.delete(cluster.vmware_attributes)
     self.env.db.flush()
     self.assertNotRaises(AttributeError, info.get_clusters_info)
    def test_all_cluster_data_collected(self):
        self.env.create(nodes_kwargs=[{"roles": ["compute"]}])
        self.env.create_node(status=consts.NODE_STATUSES.discover)

        # Fetching installation info struct
        info = InstallationInfo()
        info = info.get_installation_info()
        actual_cluster = info["clusters"][0]

        # Creating cluster schema
        cluster_schema = {}
        for column in inspect(cluster_model.Cluster).columns:
            cluster_schema[six.text_type(column.name)] = None
        for rel in inspect(cluster_model.Cluster).relationships:
            cluster_schema[six.text_type(rel.table.name)] = None

        # Removing of not required fields
        remove_fields = (
            "tasks",
            "cluster_changes",
            "nodegroups",
            "pending_release_id",
            "releases",
            "replaced_provisioning_info",
            "notifications",
            "deployment_tasks",
            "name",
            "replaced_deployment_info",
            "ui_settings",
        )
        for field in remove_fields:
            cluster_schema.pop(field)
        # Renaming fields for matching
        rename_fields = (
            ("plugins", "installed_plugins"),
            ("networking_configs", "network_configuration"),
            ("release_id", "release"),
        )
        for name_from, name_to in rename_fields:
            cluster_schema.pop(name_from)
            cluster_schema[name_to] = None

        # If test failed here it means, that you have added properties
        # to cluster and they are not exported into statistics.
        # If you don't know  what to do, contact fuel-stats team please.
        for key in six.iterkeys(cluster_schema):
            self.assertIn(key, actual_cluster)
    def test_nodes_info(self):
        info = InstallationInfo()
        self.env.create(
            release_kwargs={'operating_system': consts.RELEASE_OS.centos},
            nodes_kwargs=[{
                'status': consts.NODE_STATUSES.discover,
                'roles': ['controller', 'compute']
            }, {
                'roles': [],
                'pending_roles': ['compute']
            }])
        self.env.make_bond_via_api('bond0',
                                   consts.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])
Beispiel #29
0
    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_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_clusters_info(self):
        self.env.upload_fixtures(["openstack"])
        info = InstallationInfo()
        release = ReleaseCollection.filter_by(None, operating_system=consts.RELEASE_OS.ubuntu)
        nodes_params = [{"roles": ["compute"]}, {"roles": ["compute"]}, {"roles": ["controller"]}]
        self.env.create(
            cluster_kwargs={
                "release_id": release[0].id,
                "mode": consts.CLUSTER_MODES.ha_compact,
                "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_compact, 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, info.attributes_white_list)
     self.assertEqual(
         # No vlan splinters for ubuntu.
         # And no mellanox related entries since 8.0.
         set(attr_key_list) - set(
             ('vlan_splinters', 'vlan_splinters_ovs',
              'mellanox', 'mellanox_vf_num', 'iser')),
         set(attrs_dict.keys())
     )
    def test_nodes_info(self):
        info = InstallationInfo()
        cluster = self.env.create(release_kwargs={"operating_system": consts.RELEASE_OS.centos})
        self.env.create_nodes_w_interfaces_count(
            nodes_count=2, if_count=4, roles=["controller", "compute"], pending_addition=True, cluster_id=cluster["id"]
        )

        self.env.make_bond_via_api(
            "bond0", consts.BOND_MODES.active_backup, ["eth1", "eth2"], 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.assertIn("meta", node_info)
            for iface in node_info["meta"]["interfaces"]:
                self.assertNotIn("mac", iface)
            self.assertNotIn("fqdn", node_info["meta"]["system"])
            self.assertNotIn("serial", node_info["meta"]["system"])

            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],
            )
Beispiel #34
0
 def test_get_attributes_centos(self):
     self.skipTest('CentOS is unavailable in current release.')
     self.env.upload_fixtures(['openstack'])
     releases = ReleaseCollection.filter_by(
         None, operating_system=consts.RELEASE_OS.centos)
     release = releases[0]
     info = InstallationInfo()
     attr_key_list = [a[1] for a in info.attributes_white_list]
     # No UCA configs for CentOS.
     expected_attributes = set(attr_key_list) - set(
         ('pin_haproxy', 'repo_type', 'pin_ceph', 'pin_rabbitmq'))
     self._do_test_attributes_in_white_list(release, expected_attributes)
Beispiel #35
0
 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))
Beispiel #36
0
    def test_plugins_info(self):
        info = InstallationInfo()

        cluster = self.env.create_cluster(api=False)

        plugin_kwargs = self.env.get_default_plugin_metadata()
        plugin_obj = plugins.Plugin(**plugin_kwargs)

        self.db.add(plugin_obj)
        self.db.flush()

        plugin_kwargs["id"] = plugin_obj.id

        cluster_plugin_kwargs = {
            "cluster_id": cluster.id,
            "plugin_id": plugin_obj.id,
            "enabled": True
        }
        cluster_plugin = plugins.ClusterPlugins(**cluster_plugin_kwargs)

        self.db.add(cluster_plugin)
        self.db.flush()

        expected_attributes_names = (
            "id",
            "name",
            "version",
            "releases",
            "fuel_version",
            "package_version",
        )

        expected_info = dict([(key, value)
                              for key, value in six.iteritems(plugin_kwargs)
                              if key in expected_attributes_names])

        expected = [expected_info]
        actual = info.get_cluster_plugins_info(cluster)
        self.assertEqual(expected, actual)
Beispiel #37
0
 def test_get_attributes_ubuntu_uca(self):
     self.env.upload_fixtures(['openstack'])
     releases = ReleaseCollection.filter_by(
         None, operating_system=consts.RELEASE_OS.ubuntu).order_by(
             ReleaseCollection.single.model.id)
     release = releases[1]
     info = InstallationInfo()
     attr_key_list = [a[1] for a in info.attributes_white_list]
     # No vlan splinters for Ubuntu, no mellanox related entries
     # since 8.0.
     expected_attributes = set(attr_key_list) - set(
         ('vlan_splinters', 'vlan_splinters_ovs', 'mellanox',
          'mellanox_vf_num', 'iser'))
     self._do_test_attributes_in_white_list(release, expected_attributes)
Beispiel #38
0
    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_all_cluster_data_collected(self):
        self.env.create(nodes_kwargs=[{'roles': ['compute']}])
        self.env.create_node(status=consts.NODE_STATUSES.discover)

        # Fetching installation info struct
        info = InstallationInfo()
        info = info.get_installation_info()
        actual_cluster = info['clusters'][0]

        cluster_schema = self.get_model_schema(models.Cluster)

        # Removing of not required fields
        remove_fields = (
            'tasks', 'cluster_changes', 'nodegroups',
            'releases', 'replaced_provisioning_info', 'notifications',
            'cluster_deployment_graphs', 'name', 'replaced_deployment_info',
            'ui_settings'
        )
        for field in remove_fields:
            cluster_schema.pop(field)
        # Renaming fields for matching
        rename_fields = (
            ('plugins', 'installed_plugins'),
            ('networking_configs', 'network_configuration'),
            ('release_id', 'release'),
            ('cluster_plugin_links', 'plugin_links'),
        )
        for name_from, name_to in rename_fields:
            cluster_schema.pop(name_from)
            cluster_schema[name_to] = None

        # If test failed here it means, that you have added properties
        # to cluster and they are not exported into statistics.
        # If you don't know  what to do, contact fuel-stats team please.
        for key in six.iterkeys(cluster_schema):
            self.assertIn(key, actual_cluster)
    def test_all_node_data_collected(self):
        cluster = self.env.create_cluster(api=False)
        self.env.create_node(cluster_id=cluster.id)

        # Fetching nodes info
        info = InstallationInfo().get_nodes_info(cluster.nodes)
        actual_node = info[0]

        node_schema = self.get_model_schema(models.Node)

        # Removing of not required fields
        remove_fields = (
            'ip',
            'uuid',
            'agent_checksum',
            'hostname',
            'timestamp',
            'replaced_provisioning_info',
            'replaced_deployment_info',
            'mac',
            # Related tables
            'clusters',
            'cluster_changes',
            'nodegroups',
            'ip_addrs',
            'node_nic_interfaces',
            'node_bond_interfaces',
            'network_groups',
            'node_nic_interface_cluster_plugins',
            'node_bond_interface_cluster_plugins',
            'node_cluster_plugins',
            'node_tags')
        for field in remove_fields:
            node_schema.pop(field)

        # Renaming fields for matching
        rename_fields = (('os_platform', 'os'), )

        for name_from, name_to in rename_fields:
            node_schema.pop(name_from)
            node_schema[name_to] = None

        # If test failed here it means, that you have added properties
        # to node and they are not exported into statistics.
        # If you don't know what to do, contact fuel-stats team please.
        for key in six.iterkeys(node_schema):
            self.assertIn(key, actual_node)
Beispiel #41
0
 def send_data_to_url(self, url, data):
     resp = None
     try:
         headers = {
             'content-type': 'application/json',
             'master-node-uid': InstallationInfo().get_master_node_uid()
         }
         resp = requests.post(url,
                              headers=headers,
                              data=jsonutils.dumps(data),
                              timeout=settings.COLLECTOR_RESP_TIMEOUT)
     except (urllib3.exceptions.DecodeError, urllib3.exceptions.ProxyError,
             requests.exceptions.ConnectionError,
             requests.exceptions.Timeout,
             requests.exceptions.TooManyRedirects) as e:
         logger.error("Sending data to collector failed: %s",
                      type(e).__name__)
     except Exception as e:
         logger.exception("Sending data to collector failed: %s",
                          six.text_type(e))
     return resp
Beispiel #42
0
    def test_all_plugin_data_collected(self):
        cluster = self.env.create_cluster(api=False)
        self.env.create_plugin(api=False, cluster=cluster)

        # Fetching plugin info
        info = InstallationInfo().get_cluster_plugins_info(cluster)
        actual_plugin = info[0]

        plugin_schema = self.get_model_schema(models.Plugin,
                                              with_relationships=False)

        # Removing of not required fields
        remove_fields = ('description', 'title', 'authors', 'homepage')
        for field in remove_fields:
            plugin_schema.pop(field)

        # If test failed here it means, that you have added properties
        # to plugin and they are not exported into statistics.
        # If you don't know what to do, contact fuel-stats team please.
        for key in six.iterkeys(plugin_schema):
            self.assertIn(key, actual_plugin)
 def test_get_empty_attributes(self):
     info = InstallationInfo()
     trash_attrs = {"some": "trash", "nested": {"n": "t"}}
     result = info.get_attributes(trash_attrs, info.attributes_white_list)
     self.assertDictEqual({}, result)
Beispiel #44
0
 def test_get_empty_attributes(self):
     info = InstallationInfo()
     trash_attrs = {'some': 'trash', 'nested': {'n': 't'}}
     result = info.get_attributes(trash_attrs, info.attributes_white_list)
     self.assertDictEqual({}, result)
Beispiel #45
0
 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, info.attributes_white_list)
     self.assertDictEqual({}, result)
 def test_release_info(self):
     info = InstallationInfo()
     f_info = info.fuel_release_info()
     self.assertDictEqual(f_info, settings.VERSION)
Beispiel #48
0
 def test_user_contacts_info_disabled_while_not_confirmed_by_user(self):
     self.assertDictEqual(
         InstallationInfo().get_installation_info()['user_information'],
         {'contact_info_provided': False})