Exemplo n.º 1
0
    def test_update_state_upgrade_networking_invalid_state(self):
        # Test updating the state of an upgrade to upgrade networking in an
        # invalid state

        # Create the upgrade
        dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADING_KUBELETS)

        # Update state
        new_state = kubernetes.KUBE_UPGRADING_NETWORKING
        result = self.patch_json('/kube_upgrade', [{
            'path': '/state',
            'value': new_state,
            'op': 'replace'
        }],
                                 headers={'User-Agent': 'sysinv-test'},
                                 expect_errors=True)

        # Verify the failure
        self.assertEqual(result.content_type, 'application/json')
        self.assertEqual(http_client.BAD_REQUEST, result.status_int)
        self.assertIn("Kubernetes upgrade must be in",
                      result.json['error_message'])
Exemplo n.º 2
0
    def test_update_state_complete_incomplete_host(self):
        # Test updating the state of an upgrade to complete when a host has
        # not completed its upgrade
        self.kube_get_version_states_result = {'v1.42.1': 'available',
                                               'v1.42.2': 'available',
                                               'v1.43.1': 'available',
                                               'v1.43.2': 'active',
                                               'v1.43.3': 'available'}

        # Create the upgrade
        dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADING_KUBELETS)

        # Mark the kube host upgrade as failed
        values = {
            'status': kubernetes.KUBE_HOST_UPGRADING_CONTROL_PLANE_FAILED
        }
        self.dbapi.kube_host_upgrade_update(1, values)

        # Update state
        new_state = kubernetes.KUBE_UPGRADE_COMPLETE
        result = self.patch_json('/kube_upgrade',
                                 [{'path': '/state',
                                   'value': new_state,
                                   'op': 'replace'}],
                                 headers={'User-Agent': 'sysinv-test'},
                                 expect_errors=True)

        # Verify the failure
        self.assertEqual(result.content_type, 'application/json')
        self.assertEqual(http_client.BAD_REQUEST, result.status_int)
        self.assertIn("At least one host has not completed",
                      result.json['error_message'])
Exemplo n.º 3
0
    def test_all(self):
        dbutils.create_test_kube_upgrade(
            from_version='v1.42.1',
            to_version='v1.42.2',
            state=kubernetes.KUBE_UPGRADING_FIRST_MASTER,
        )

        # Verify that the upgrade has the expected attributes
        data = self.get_json('/kube_upgrade')
        self.assertEqual(1, len(data['kube_upgrades']))
        self.assertEqual(data['kube_upgrades'][0]['from_version'], 'v1.42.1')
        self.assertEqual(data['kube_upgrades'][0]['to_version'], 'v1.42.2')
        self.assertEqual(data['kube_upgrades'][0]['state'],
                         kubernetes.KUBE_UPGRADING_FIRST_MASTER)
Exemplo n.º 4
0
 def test_patch_oam_during_kubernetes_upgrade(self):
     oam_floating_ip = self.oam_subnet[2]
     oam_c0_ip = self.oam_subnet[3]
     oam_c1_ip = self.oam_subnet[4]
     patch_obj = {
         'oam_floating_ip': str(oam_floating_ip),
         'oam_c0_ip': str(oam_c0_ip),
         'oam_c1_ip': str(oam_c1_ip),
     }
     dbutils.create_test_kube_upgrade()
     error_message = "Action rejected while a " \
                     "kubernetes upgrade is in progress"
     self._test_patch_fail(patch_obj, http_client.BAD_REQUEST,
                           error_message)
Exemplo n.º 5
0
    def test_update_state_upgrade_networking_after_failure(self):
        # Test updating the state of an upgrade to upgrade networking after a
        # failure

        # Create the upgrade
        kube_upgrade = dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADING_NETWORKING_FAILED)
        uuid = kube_upgrade.uuid

        # Update state
        new_state = kubernetes.KUBE_UPGRADING_NETWORKING
        response = self.patch_json('/kube_upgrade', [{
            'path': '/state',
            'value': new_state,
            'op': 'replace'
        }],
                                   headers={'User-Agent': 'sysinv-test'})
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, http_client.OK)
        self.assertEqual(response.json['from_version'], 'v1.43.1')
        self.assertEqual(response.json['to_version'], 'v1.43.2')
        self.assertEqual(response.json['state'], new_state)

        # Verify that networking was upgraded
        self.fake_conductor_api.kube_upgrade_networking.\
            assert_called_with(mock.ANY, 'v1.43.2')

        # Verify that the upgrade was updated with the new state
        result = self.get_json('/kube_upgrade/%s' % uuid)
        self.assertEqual(result['from_version'], 'v1.43.1')
        self.assertEqual(result['to_version'], 'v1.43.2')
        self.assertEqual(result['state'], new_state)
Exemplo n.º 6
0
    def test_update_state_download_images(self):
        # Test updating the state of an upgrade to download images

        # Create the upgrade
        kube_upgrade = dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADE_STARTED)
        uuid = kube_upgrade.uuid

        # Update state
        new_state = kubernetes.KUBE_UPGRADE_DOWNLOADING_IMAGES
        response = self.patch_json('/kube_upgrade', [{
            'path': '/state',
            'value': new_state,
            'op': 'replace'
        }],
                                   headers={'User-Agent': 'sysinv-test'})
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, http_client.OK)
        self.assertEqual(response.json['from_version'], 'v1.43.1')
        self.assertEqual(response.json['to_version'], 'v1.43.2')
        self.assertEqual(response.json['state'], new_state)

        # Verify that the images were downloaded
        self.fake_conductor_api.kube_download_images.\
            assert_called_with(mock.ANY, 'v1.43.2')

        # Verify that the upgrade was updated with the new state
        result = self.get_json('/kube_upgrade/%s' % uuid)
        self.assertEqual(result['from_version'], 'v1.43.1')
        self.assertEqual(result['to_version'], 'v1.43.2')
        self.assertEqual(result['state'], new_state)
Exemplo n.º 7
0
    def test_update_state_complete(self):
        # Test updating the state of an upgrade to complete
        self.kube_get_version_states_result = {'v1.42.1': 'available',
                                               'v1.42.2': 'available',
                                               'v1.43.1': 'available',
                                               'v1.43.2': 'active',
                                               'v1.43.3': 'available'}

        # Create the upgrade
        kube_upgrade = dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADING_KUBELETS)
        uuid = kube_upgrade.uuid

        # Update state
        new_state = kubernetes.KUBE_UPGRADE_COMPLETE
        response = self.patch_json('/kube_upgrade',
                                   [{'path': '/state',
                                     'value': new_state,
                                     'op': 'replace'}],
                                   headers={'User-Agent': 'sysinv-test'})
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, http_client.OK)
        self.assertEqual(response.json['from_version'], 'v1.43.1')
        self.assertEqual(response.json['to_version'], 'v1.43.2')
        self.assertEqual(response.json['state'], new_state)

        # Verify that the upgrade was updated with the new state
        result = self.get_json('/kube_upgrade/%s' % uuid)
        self.assertEqual(result['from_version'], 'v1.43.1')
        self.assertEqual(result['to_version'], 'v1.43.2')
        self.assertEqual(result['state'], new_state)
Exemplo n.º 8
0
    def test_create_upgrade_exists(self):
        # Test creation of upgrade when upgrade already exists
        dbutils.create_test_kube_upgrade(
            from_version='v1.42.1',
            to_version='v1.42.2',
            state=kubernetes.KUBE_UPGRADING_FIRST_MASTER,
        )
        create_dict = dbutils.post_get_test_kube_upgrade(to_version='v1.43.2')
        result = self.post_json('/kube_upgrade', create_dict,
                                headers={'User-Agent': 'sysinv-test'},
                                expect_errors=True)

        # Verify the failure
        self.assertEqual(result.content_type, 'application/json')
        self.assertEqual(http_client.BAD_REQUEST, result.status_int)
        self.assertIn("upgrade is already in progress",
                      result.json['error_message'])
Exemplo n.º 9
0
    def test_delete_upgrade_not_complete(self):
        # Test deleting an upgrade when upgrade is not complete

        # Create the upgrade
        dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADING_FIRST_MASTER)

        # Delete the upgrade
        result = self.delete('/kube_upgrade',
                             headers={'User-Agent': 'sysinv-test'},
                             expect_errors=True)

        # Verify the failure
        self.assertEqual(result.content_type, 'application/json')
        self.assertEqual(http_client.BAD_REQUEST, result.status_int)
        self.assertIn("upgrade must be in upgrade-complete",
                      result.json['error_message'])
    def test_all_upgrade_target(self):
        # Create an upgrade
        dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADE_DOWNLOADED_IMAGES,
        )

        data = self.get_json('/kube_versions')
        self.assertEqual(len(FAKE_KUBE_VERSIONS), len(data['kube_versions']))

        index = 0
        for result in data['kube_versions']:
            self.assertEqual(result['version'],
                             FAKE_KUBE_VERSIONS[index]['version'])
            self.assertEqual(result['state'],
                             FAKE_KUBE_STATES[result['version']])
            self.assertEqual(result['target'],
                             True if result['version'] == 'v1.43.2' else False)
            index += 1
    def test_one_upgrade_target(self):
        # Create an upgrade
        dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADE_DOWNLOADED_IMAGES,
        )

        result = self.get_json('/kube_versions/v1.43.2')

        # Verify that the version has the expected attributes
        self.assertEqual(result['version'], FAKE_KUBE_VERSIONS[3]['version'])
        self.assertEqual(result['upgrade_from'],
                         FAKE_KUBE_VERSIONS[3]['upgrade_from'])
        self.assertEqual(result['downgrade_to'],
                         FAKE_KUBE_VERSIONS[3]['downgrade_to'])
        self.assertEqual(result['applied_patches'],
                         FAKE_KUBE_VERSIONS[3]['applied_patches'])
        self.assertEqual(result['available_patches'],
                         FAKE_KUBE_VERSIONS[3]['available_patches'])
        self.assertEqual(result['state'], 'available')
        self.assertEqual(result['target'], True)
Exemplo n.º 12
0
    def test_one(self):
        kube_upgrade = dbutils.create_test_kube_upgrade(
            from_version='v1.42.1',
            to_version='v1.42.2',
            state=kubernetes.KUBE_UPGRADING_FIRST_MASTER,
        )
        result = self.get_json('/kube_upgrade/%s' % kube_upgrade['uuid'])

        # Verify that the upgrade has the expected attributes
        self.assertEqual(result['from_version'], 'v1.42.1')
        self.assertEqual(result['to_version'], 'v1.42.2')
        self.assertEqual(result['state'],
                         kubernetes.KUBE_UPGRADING_FIRST_MASTER)
Exemplo n.º 13
0
    def test_update_state_bad_state(self):
        # Test updating the state of an upgrade with a bad state

        # Create the upgrade
        dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADED_FIRST_MASTER)

        # Update state
        new_state = 'this-is-a-bad-state'
        result = self.patch_json('/kube_upgrade', [{
            'path': '/state',
            'value': new_state,
            'op': 'replace'
        }],
                                 headers={'User-Agent': 'sysinv-test'},
                                 expect_errors=True)

        # Verify the failure
        self.assertEqual(result.content_type, 'application/json')
        self.assertEqual(http_client.BAD_REQUEST, result.status_int)
        self.assertIn("Invalid state", result.json['error_message'])
Exemplo n.º 14
0
    def test_delete(self):
        # Test deleting an upgrade

        # Create the upgrade
        kube_upgrade = dbutils.create_test_kube_upgrade(
            from_version='v1.43.1',
            to_version='v1.43.2',
            state=kubernetes.KUBE_UPGRADE_COMPLETE)

        # Delete the upgrade
        self.delete('/kube_upgrade', headers={'User-Agent': 'sysinv-test'})

        # Verify the upgrade no longer exists
        response = self.get_json('/kube_upgrade/%s' % kube_upgrade.uuid,
                                 expect_errors=True)
        self.assertEqual(response.status_int, 404)
        self.assertEqual(response.content_type, 'application/json')
        self.assertTrue(response.json['error_message'])
Exemplo n.º 15
0
    def test_kube_upgrades(self):
        # Test kube_upgrade and kube_host_upgrade table creation
        upgrade = utils.create_test_kube_upgrade()
        host_upgrade = utils.create_test_kube_host_upgrade()

        # Test updating state in kube_upgrade table
        old_state = upgrade['state']
        new_state = 'upgrading'
        self.assertNotEqual(old_state, new_state)

        res = self.dbapi.kube_upgrade_update(upgrade['id'],
                                             {'state': new_state})
        self.assertEqual(new_state, res['state'])

        # Test updating status in kube_host_upgrade table
        old_status = host_upgrade['status']
        new_status = new_state
        self.assertNotEqual(old_status, new_status)

        res = self.dbapi.kube_host_upgrade_update(host_upgrade['uuid'],
                                                  {'status': new_status})
        self.assertEqual(new_status, res['status'])