Skip to content

Commit

Permalink
Update testing docs
Browse files Browse the repository at this point in the history
Signed-off-by: innobead <[email protected]>
  • Loading branch information
innobead committed Dec 29, 2023
1 parent 3957814 commit 2b6e345
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 3 deletions.
33 changes: 32 additions & 1 deletion integration/common.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ <h1 class="title">Module <code>tests.common</code></h1>
SETTING_BACKUP_COMPRESSION_METHOD = &#34;backup-compression-method&#34;
SETTING_BACKUP_CONCURRENT_LIMIT = &#34;backup-concurrent-limit&#34;
SETTING_RESTORE_CONCURRENT_LIMIT = &#34;restore-concurrent-limit&#34;
SETTING_V1_DATA_ENGINE = &#34;v1-data-engine&#34;

DEFAULT_BACKUP_COMPRESSION_METHOD = &#34;lz4&#34;
BACKUP_COMPRESSION_METHOD_LZ4 = &#34;lz4&#34;
Expand Down Expand Up @@ -6049,7 +6050,17 @@ <h1 class="title">Module <code>tests.common</code></h1>
# Step 2
volume_data = write_volume_random_data(volume)

return volume, volume_data</code></pre>
return volume, volume_data


def wait_for_instance_manager_count(client, number, retry_counts=120):
for _ in range(retry_counts):
ims = client.list_instance_manager()
if len(ims) == number:
break
time.sleep(RETRY_INTERVAL_LONG)

return len(ims)</code></pre>
</details>
</section>
<section>
Expand Down Expand Up @@ -13130,6 +13141,25 @@ <h2 id="returns">Returns</h2>
assert failed</code></pre>
</details>
</dd>
<dt id="tests.common.wait_for_instance_manager_count"><code class="name flex">
<span>def <span class="ident">wait_for_instance_manager_count</span></span>(<span>client, number, retry_counts=120)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def wait_for_instance_manager_count(client, number, retry_counts=120):
for _ in range(retry_counts):
ims = client.list_instance_manager()
if len(ims) == number:
break
time.sleep(RETRY_INTERVAL_LONG)

return len(ims)</code></pre>
</details>
</dd>
<dt id="tests.common.wait_for_instance_manager_desire_state"><code class="name flex">
<span>def <span class="ident">wait_for_instance_manager_desire_state</span></span>(<span>client, core_api, im_name, state, desire=True)</span>
</code></dt>
Expand Down Expand Up @@ -15303,6 +15333,7 @@ <h1>Index</h1>
<li><code><a title="tests.common.wait_for_engine_image_state" href="#tests.common.wait_for_engine_image_state">wait_for_engine_image_state</a></code></li>
<li><code><a title="tests.common.wait_for_expansion_error_clear" href="#tests.common.wait_for_expansion_error_clear">wait_for_expansion_error_clear</a></code></li>
<li><code><a title="tests.common.wait_for_expansion_failure" href="#tests.common.wait_for_expansion_failure">wait_for_expansion_failure</a></code></li>
<li><code><a title="tests.common.wait_for_instance_manager_count" href="#tests.common.wait_for_instance_manager_count">wait_for_instance_manager_count</a></code></li>
<li><code><a title="tests.common.wait_for_instance_manager_desire_state" href="#tests.common.wait_for_instance_manager_desire_state">wait_for_instance_manager_desire_state</a></code></li>
<li><code><a title="tests.common.wait_for_node_mountpropagation_condition" href="#tests.common.wait_for_node_mountpropagation_condition">wait_for_node_mountpropagation_condition</a></code></li>
<li><code><a title="tests.common.wait_for_node_schedulable_condition" href="#tests.common.wait_for_node_schedulable_condition">wait_for_node_schedulable_condition</a></code></li>
Expand Down
142 changes: 140 additions & 2 deletions integration/test_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ <h1 class="title">Module <code>tests.test_settings</code></h1>
get_engine_image_status_value,
create_volume, create_volume_and_backup, cleanup_volume_by_name,
wait_for_volume_restoration_completed, wait_for_backup_restore_completed,
get_engine_host_id,
get_engine_host_id, wait_for_instance_manager_count,
Gi, Mi,

LONGHORN_NAMESPACE,
Expand All @@ -60,6 +60,7 @@ <h1 class="title">Module <code>tests.test_settings</code></h1>
SETTING_DEFAULT_REPLICA_COUNT,
SETTING_BACKUP_TARGET,
SETTING_CONCURRENT_VOLUME_BACKUP_RESTORE,
SETTING_V1_DATA_ENGINE,
RETRY_COUNTS, RETRY_INTERVAL, RETRY_INTERVAL_LONG,
update_setting, BACKING_IMAGE_QCOW2_URL, BACKING_IMAGE_NAME,
create_backing_image_with_matching_url, BACKING_IMAGE_EXT4_SIZE,
Expand Down Expand Up @@ -1268,7 +1269,67 @@ <h1 class="title">Module <code>tests.test_settings</code></h1>
[target,
&#34;&#34;])

cleanup_volume_by_name(client, vol_name)</code></pre>
cleanup_volume_by_name(client, vol_name)


def test_setting_v1_data_engine(client, request): # NOQA
&#34;&#34;&#34;
Test that the v1 data engine setting works correctly.
1. Create a volume and attach it.
2. Set v1 data engine setting to false. The setting should be rejected.
3. Detach the volume.
4. Set v1 data engine setting to false again. The setting should be
accepted. Then, attach the volume. The volume is unable to attach.
5. set v1 data engine setting to true. The setting should be accepted.
6. Attach the volume.
&#34;&#34;&#34;

setting = client.by_id_setting(SETTING_V1_DATA_ENGINE)

# Step 1
volume_name = &#34;test-v1-vol&#34; # NOQA
volume = create_and_check_volume(client, volume_name)

def finalizer():
cleanup_volume(client, volume)
client.update(setting, value=&#34;true&#34;)

request.addfinalizer(finalizer)

volume.attach(hostId=get_self_host_id())
volume = wait_for_volume_healthy(client, volume_name)

# Step 2
with pytest.raises(Exception) as e:
client.update(setting, value=&#34;false&#34;)
assert &#39;cannot apply v1-data-engine setting to Longhorn workloads when &#39; \
&#39;there are attached v1 volumes&#39; in str(e.value)

# Step 3
volume.detach()
wait_for_volume_detached(client, volume_name)

# Step 4
setting = client.by_id_setting(SETTING_V1_DATA_ENGINE)
client.update(setting, value=&#34;false&#34;)

count = wait_for_instance_manager_count(client, 0)
assert count == 0

volume.attach(hostId=get_self_host_id())
with pytest.raises(Exception) as e:
wait_for_volume_healthy(client, volume_name)
assert &#39;volume[key]=detached&#39; in str(e.value)

# Step 5
client.update(setting, value=&#34;true&#34;)
nodes = client.list_node()
count = wait_for_instance_manager_count(client, len(nodes))
assert count == len(nodes)

# Step 6
volume.attach(hostId=get_self_host_id())
volume = wait_for_volume_healthy(client, volume_name)</code></pre>
</details>
</section>
<section>
Expand Down Expand Up @@ -2715,6 +2776,82 @@ <h2 class="section-title" id="header-functions">Functions</h2>
cleanup_volume_by_name(client, vol_name)</code></pre>
</details>
</dd>
<dt id="tests.test_settings.test_setting_v1_data_engine"><code class="name flex">
<span>def <span class="ident">test_setting_v1_data_engine</span></span>(<span>client, request)</span>
</code></dt>
<dd>
<div class="desc"><p>Test that the v1 data engine setting works correctly.
1. Create a volume and attach it.
2. Set v1 data engine setting to false. The setting should be rejected.
3. Detach the volume.
4. Set v1 data engine setting to false again. The setting should be
accepted. Then, attach the volume. The volume is unable to attach.
5. set v1 data engine setting to true. The setting should be accepted.
6. Attach the volume.</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def test_setting_v1_data_engine(client, request): # NOQA
&#34;&#34;&#34;
Test that the v1 data engine setting works correctly.
1. Create a volume and attach it.
2. Set v1 data engine setting to false. The setting should be rejected.
3. Detach the volume.
4. Set v1 data engine setting to false again. The setting should be
accepted. Then, attach the volume. The volume is unable to attach.
5. set v1 data engine setting to true. The setting should be accepted.
6. Attach the volume.
&#34;&#34;&#34;

setting = client.by_id_setting(SETTING_V1_DATA_ENGINE)

# Step 1
volume_name = &#34;test-v1-vol&#34; # NOQA
volume = create_and_check_volume(client, volume_name)

def finalizer():
cleanup_volume(client, volume)
client.update(setting, value=&#34;true&#34;)

request.addfinalizer(finalizer)

volume.attach(hostId=get_self_host_id())
volume = wait_for_volume_healthy(client, volume_name)

# Step 2
with pytest.raises(Exception) as e:
client.update(setting, value=&#34;false&#34;)
assert &#39;cannot apply v1-data-engine setting to Longhorn workloads when &#39; \
&#39;there are attached v1 volumes&#39; in str(e.value)

# Step 3
volume.detach()
wait_for_volume_detached(client, volume_name)

# Step 4
setting = client.by_id_setting(SETTING_V1_DATA_ENGINE)
client.update(setting, value=&#34;false&#34;)

count = wait_for_instance_manager_count(client, 0)
assert count == 0

volume.attach(hostId=get_self_host_id())
with pytest.raises(Exception) as e:
wait_for_volume_healthy(client, volume_name)
assert &#39;volume[key]=detached&#39; in str(e.value)

# Step 5
client.update(setting, value=&#34;true&#34;)
nodes = client.list_node()
count = wait_for_instance_manager_count(client, len(nodes))
assert count == len(nodes)

# Step 6
volume.attach(hostId=get_self_host_id())
volume = wait_for_volume_healthy(client, volume_name)</code></pre>
</details>
</dd>
<dt id="tests.test_settings.update_settings_via_configmap"><code class="name flex">
<span>def <span class="ident">update_settings_via_configmap</span></span>(<span>core_api, client, setting_names, setting_values, request)</span>
</code></dt>
Expand Down Expand Up @@ -2927,6 +3064,7 @@ <h1>Index</h1>
<li><code><a title="tests.test_settings.test_setting_toleration" href="#tests.test_settings.test_setting_toleration">test_setting_toleration</a></code></li>
<li><code><a title="tests.test_settings.test_setting_toleration_extra" href="#tests.test_settings.test_setting_toleration_extra">test_setting_toleration_extra</a></code></li>
<li><code><a title="tests.test_settings.test_setting_update_with_invalid_value_via_configmap" href="#tests.test_settings.test_setting_update_with_invalid_value_via_configmap">test_setting_update_with_invalid_value_via_configmap</a></code></li>
<li><code><a title="tests.test_settings.test_setting_v1_data_engine" href="#tests.test_settings.test_setting_v1_data_engine">test_setting_v1_data_engine</a></code></li>
<li><code><a title="tests.test_settings.update_settings_via_configmap" href="#tests.test_settings.update_settings_via_configmap">update_settings_via_configmap</a></code></li>
<li><code><a title="tests.test_settings.validate_settings" href="#tests.test_settings.validate_settings">validate_settings</a></code></li>
<li><code><a title="tests.test_settings.wait_for_longhorn_node_ready" href="#tests.test_settings.wait_for_longhorn_node_ready">wait_for_longhorn_node_ready</a></code></li>
Expand Down

0 comments on commit 2b6e345

Please sign in to comment.