Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 1 | # Copyright 2017 Mirantis, Inc. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | import pytest |
| 15 | import time |
| 16 | |
| 17 | from tcp_tests import logger |
| 18 | |
| 19 | LOG = logger.logger |
| 20 | |
| 21 | |
| 22 | class TestFailoverK8s(object): |
| 23 | |
Vladimir Jigulin | 2154e4b | 2018-11-14 12:14:05 +0400 | [diff] [blame] | 24 | @pytest.mark.grab_versions |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 25 | @pytest.mark.fail_snapshot |
Vladimir Jigulin | eb8b813 | 2019-03-19 15:34:02 +0400 | [diff] [blame] | 26 | @pytest.mark.k8s_system |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 27 | def test_k8s_master_vip_migration(self, show_step, k8s_deployed, underlay, |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 28 | k8s_actions, core_actions, |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 29 | config, hardware): |
| 30 | """Test restart and shutdown master with VIP |
| 31 | |
| 32 | Scenario: |
| 33 | 1. Deploy mcp with k8s ha |
| 34 | 2. Check keepalived pillar configuration |
| 35 | 3. Find master node with assigned VIP |
| 36 | 4. Reboot server with VIP |
| 37 | 5. Check that VIP was migrated |
| 38 | 6. Check keepalived pillar configuration |
| 39 | 7. Check api server availability |
| 40 | 8. Run conformance on node with VIP |
| 41 | """ |
| 42 | show_step(1) |
| 43 | show_step(2) |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 44 | core_actions.check_keepalived_pillar() |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 45 | |
| 46 | show_step(3) |
| 47 | vip = k8s_actions.get_keepalived_vip() |
| 48 | LOG.info("VIP ip address: {}".format(vip)) |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 49 | minion_vip = core_actions.get_keepalived_vip_minion_id(vip) |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 50 | LOG.info("VIP {0} is on {1}".format(vip, minion_vip)) |
| 51 | |
| 52 | show_step(4) |
| 53 | hardware.warm_restart_nodes(underlay, minion_vip) |
| 54 | |
| 55 | show_step(5) |
| 56 | try: |
| 57 | new_minion_vip =\ |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 58 | core_actions.get_keepalived_vip_minion_id(vip) |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 59 | except Exception: |
Dennis Dmitriev | 7cab548 | 2019-05-22 15:40:14 +0300 | [diff] [blame] | 60 | time.sleep(15) |
| 61 | new_minion_vip = \ |
| 62 | core_actions.get_keepalived_vip_minion_id(vip) |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 63 | LOG.info("VIP {0} migrated to {1}".format(vip, new_minion_vip)) |
| 64 | assert new_minion_vip != minion_vip |
| 65 | |
| 66 | show_step(6) |
Dennis Dmitriev | ea48cf5 | 2018-07-18 18:04:39 +0300 | [diff] [blame] | 67 | core_actions.check_keepalived_pillar() |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 68 | |
| 69 | show_step(7) |
| 70 | curl_output = ''.join(underlay.check_call( |
| 71 | cmd="curl -k -s 'https://{}'".format(vip), |
| 72 | host=config.salt.salt_master_host, raise_on_err=False)['stdout']) |
| 73 | assert "apiVersion" in curl_output |
| 74 | |
Vladimir Jigulin | 174aab1 | 2019-01-28 22:17:46 +0400 | [diff] [blame] | 75 | k8s_actions.renew_controller(controller_node_name=new_minion_vip) |
| 76 | |
Vladimir Jigulin | ee1faa5 | 2018-06-25 13:00:51 +0400 | [diff] [blame] | 77 | show_step(8) |
Vladimir Jigulin | 174aab1 | 2019-01-28 22:17:46 +0400 | [diff] [blame] | 78 | k8s_actions.start_conformance_inside_pod() |