Exemplo n.º 1
0
 def test_get_cluster_resources_server_error(self):
     """Ensure that function raises exception for non-404 responses."""
     self.resp.raise_for_status = MagicMock(side_effect=HTTPError())
     self.resp.status_code = 500
     self.session.get = MagicMock(return_value=self.resp)
     resource_types = ['r1']
     verify = True
     with self.assertRaises(HTTPError):
         get_cluster_resources(self.session,
                               '',
                               resource_types,
                               verify=verify)
Exemplo n.º 2
0
 def fetch_cluster_resources(self):
     """Fetch cluster resources."""
     clusters = self.config.get('org.kubernetes.cluster_resources.clusters')
     for cluster in clusters:
         token = self.config.creds.get('kubernetes',
                                       f'{cluster["label"]}_token')
         cluster['resources'] = get_cluster_resources(self.session(
             cluster['server']),
                                                      token,
                                                      self.resource_types,
                                                      verify=False)
     return json.dumps(clusters)
Exemplo n.º 3
0
 def test_get_cluster_resources_success_custom_resource(self):
     """Ensure that custom resources can be retrieved."""
     self.resp.raise_for_status = MagicMock()
     self.session.get = MagicMock(return_value=self.resp)
     resource_type = 'example.com/v1alpha1/mycustomtype'
     verify = True
     resources = get_cluster_resources(self.session,
                                       '', [resource_type],
                                       verify=verify)
     self.session.get.assert_called_once_with(f'apis/{resource_type}',
                                              verify=verify)
     self.resp.raise_for_status.assert_called_once()
     self.assertEqual(resources, {resource_type: self.data})
Exemplo n.º 4
0
 def test_get_cluster_resources_success_core_api(self):
     """Ensure that core API resources can be retrieved."""
     self.resp.raise_for_status = MagicMock()
     self.session.get = MagicMock(return_value=self.resp)
     resource_type = 'r1'
     verify = True
     resources = get_cluster_resources(self.session,
                                       '', [resource_type],
                                       verify=verify)
     self.session.get.assert_called_once_with(f'api/v1/{resource_type}',
                                              verify=verify)
     self.resp.raise_for_status.assert_called_once()
     self.assertEqual(resources, {resource_type: self.data})
Exemplo n.º 5
0
 def test_get_cluster_resources_not_found(self):
     """Ensure that function works for unfound resources."""
     self.resp.raise_for_status = MagicMock(side_effect=HTTPError())
     self.resp.status_code = 404
     self.session.get = MagicMock(return_value=self.resp)
     resource_types = ['r1']
     verify = True
     resources = get_cluster_resources(self.session,
                                       '',
                                       resource_types,
                                       verify=verify)
     self.session.get.assert_called_once_with('api/v1/r1', verify=verify)
     self.resp.raise_for_status.assert_called_once()
     self.assertEqual(resources, {})