Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alts/shared/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class OpennebulaConfig(BaseModel):
vm_group: Optional[str] = None
default_vm_disk_size: Optional[int] = 15360
default_vm_ram_size: Optional[int] = 1536
# Swapfile size in MB created during provisioning; 0 disables it
default_vm_swap_size: Optional[int] = 0
network: Optional[str] = None
# Quota checking configuration
quota_check_enabled: bool = False
Expand Down
8 changes: 8 additions & 0 deletions alts/worker/runners/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ def vm_ram_size(self) -> int:
CONFIG.opennebula_config.default_vm_ram_size,
)

@property
def vm_swap_size(self) -> int:
return self._test_env.get(
'vm_swap_size',
getattr(CONFIG.opennebula_config, 'default_vm_swap_size', 0),
)

@property
def dist_arch(self):
return self._dist_arch
Expand Down Expand Up @@ -745,6 +752,7 @@ def initial_provision(self, verbose=False):
'integrity_tests_dir': self._integrity_tests_dir,
'connection_type': self.ansible_connection_type,
'pytest_is_needed': self.pytest_is_needed,
'vm_swap_size': self.vm_swap_size,
Comment thread
anfimovdm marked this conversation as resolved.
'development_mode': CONFIG.development_mode,
'package_proxy': CONFIG.package_proxy,
'third_party_repo_ssh_hosts': [
Expand Down
1 change: 1 addition & 0 deletions alts/worker/runners/opennebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def _render_tf_main_file(self):
template_id=template_id,
vm_disk_size=self.vm_disk_size,
vm_ram_size=self.vm_ram_size,
vm_swap_size=self.vm_swap_size,
opennebula_network=CONFIG.opennebula_config.network,
)

Expand Down
1 change: 1 addition & 0 deletions configs/example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ opennebula_config:
# in MB
default_vm_disk_size:
default_vm_ram_size:
default_vm_swap_size:
network:

bs_host:
Expand Down
6 changes: 3 additions & 3 deletions resources/opennebula/opennebula.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ locals {
# Disk configuration
disk_0 = data.opennebula_template.selected_template.disk[0]
disk_size = max(
local.disk_0.size, # Original disk size from template
15360, # Minimum required size
local.disk_0.size + 5120 # Original size + 5GB
local.disk_0.size, # Original disk size from template
15360, # Minimum required size
local.disk_0.size + 5120 + ${vm_swap_size} # Original size + 5GB + swapfile (MB)
)
# Determine network_id: use template network if available, otherwise use test_system_network
network_id = local.template_has_network ? data.opennebula_virtual_network.template_network[0].id : data.opennebula_virtual_network.test_system_network.id
Expand Down
3 changes: 3 additions & 0 deletions resources/roles/preparation/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ third_party_repo_ssh_hosts: []
# and is passed in as an extra-var by the runner. Empty list here is a
# no-op fallback so the role still works if invoked standalone.
cached_test_repos: []
# Swapfile size in MB, passed in as an extra-var by the runner from the
# platform's `vm_swap_size`. 0 (the default) disables swapfile creation.
vm_swap_size: 0
39 changes: 39 additions & 0 deletions resources/roles/preparation/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,45 @@
tags:
- initial_provision

# Some platforms (e.g. CL7h) carry many available kernels across repos, and
# dnf/yum can exhaust memory while resolving kernel-module dependencies.
# A swapfile sized from the platform's `vm_swap_size` gives them headroom.
# VM-only (Docker envs share the host kernel and can't swapon) and a no-op
# when vm_swap_size is 0.
- name: Provide swap space for memory-constrained platforms
when:
- connection_type != 'docker'
- (vm_swap_size | int) > 0
tags:
- initial_provision
block:
- name: Allocate swapfile
ansible.builtin.command:
cmd: "fallocate -l {{ vm_swap_size }}M /swapfile"
creates: /swapfile

- name: Restrict swapfile permissions
ansible.builtin.file:
path: /swapfile
owner: root
group: root
mode: '0600'

- name: Format swapfile
ansible.builtin.command:
cmd: mkswap /swapfile
register: _mkswap
changed_when: _mkswap.rc == 0

- name: Enable swapfile
ansible.builtin.command:
cmd: swapon /swapfile
register: _swapon
changed_when: _swapon.rc == 0
failed_when:
- _swapon.rc != 0
- "'already active' not in _swapon.stderr"

# SSH client config is only needed where the third-party repo is cloned
# *inside* the environment (VMs cloned over SSH). Docker envs receive the
# repo via `docker cp` from the worker, so they never clone and need no
Expand Down
Loading