mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-03 14:10:29 +03:00
get_virt_memory_opt: support str values like "16GB"
This commit is contained in:
parent
2386bcc64f
commit
8421d61369
2 changed files with 34 additions and 7 deletions
|
|
@ -31,6 +31,7 @@ Since this is an internal command, the strings are not localized.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -107,6 +108,7 @@ def run_vagrant(appid, vercode, cpus, memory):
|
||||||
raise BuildException(
|
raise BuildException(
|
||||||
f"vagrant memory setting required, '{memory}' not a valid value!"
|
f"vagrant memory setting required, '{memory}' not a valid value!"
|
||||||
)
|
)
|
||||||
|
memory = int(memory / 1024**2) # libvirt.memory expects a value in MiB
|
||||||
|
|
||||||
vagrantfile = common.get_vagrantfile_path(appid, vercode)
|
vagrantfile = common.get_vagrantfile_path(appid, vercode)
|
||||||
|
|
||||||
|
|
@ -156,14 +158,19 @@ def get_virt_cpus_opt(cpus):
|
||||||
|
|
||||||
|
|
||||||
def get_virt_memory_opt(memory):
|
def get_virt_memory_opt(memory):
|
||||||
"""Read VM memory size in GB from options or return default.
|
"""Return binary VM memory size from or default value in bytes.
|
||||||
|
|
||||||
|
Since this is for memory, this only converts using power-of-two
|
||||||
|
binary forms. For example, GB is forced to GiB.
|
||||||
|
|
||||||
Defaults to 6 GB (minimum to build org.fdroid.fdroid in 2025).
|
Defaults to 6 GB (minimum to build org.fdroid.fdroid in 2025).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if memory:
|
if not memory:
|
||||||
return memory
|
memory = '6144MiB'
|
||||||
return 6144
|
return common.parse_human_readable_size(
|
||||||
|
re.sub(r'([KMGT])B$', r'\1iB', str(memory), re.IGNORECASE)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def up_wrapper(appid, vercode, virt_container_type, cpus=None, memory=None):
|
def up_wrapper(appid, vercode, virt_container_type, cpus=None, memory=None):
|
||||||
|
|
@ -187,14 +194,12 @@ def main():
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--cpus",
|
"--cpus",
|
||||||
default=None,
|
|
||||||
type=int,
|
type=int,
|
||||||
help="How many CPUs the Vagrant VM should be allocated.",
|
help="How many CPUs the Vagrant VM should be allocated.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--memory",
|
"--memory",
|
||||||
default=None,
|
type=common.parse_human_readable_size,
|
||||||
type=int,
|
|
||||||
help="How many MB of RAM the Vagrant VM should be allocated.",
|
help="How many MB of RAM the Vagrant VM should be allocated.",
|
||||||
)
|
)
|
||||||
options = common.parse_args(parser)
|
options = common.parse_args(parser)
|
||||||
|
|
|
||||||
|
|
@ -142,3 +142,25 @@ class Up_run_vagrant(UpTest):
|
||||||
up.run_vagrant(APPID, VERCODE, 1, 1)
|
up.run_vagrant(APPID, VERCODE, 1, 1)
|
||||||
vagrant_destroy.assert_called_once()
|
vagrant_destroy.assert_called_once()
|
||||||
self.assertNotEqual(ctime, os.path.getctime(vagrantfile))
|
self.assertNotEqual(ctime, os.path.getctime(vagrantfile))
|
||||||
|
|
||||||
|
|
||||||
|
class Up_options(UpTest):
|
||||||
|
def test_get_virt_memory_opt_default(self):
|
||||||
|
self.assertEqual(up.get_virt_memory_opt(None), 6 * 1024**3)
|
||||||
|
|
||||||
|
def test_get_virt_memory_opt_int(self):
|
||||||
|
testvalue = 1234567890
|
||||||
|
self.assertEqual(up.get_virt_memory_opt(testvalue), testvalue)
|
||||||
|
|
||||||
|
def test_get_virt_memory_opt_str_int(self):
|
||||||
|
testvalue = 1234567890
|
||||||
|
self.assertEqual(up.get_virt_memory_opt(str(testvalue)), testvalue)
|
||||||
|
|
||||||
|
def test_get_virt_memory_opt_str_upper(self):
|
||||||
|
self.assertEqual(up.get_virt_memory_opt('1GB'), 1024**3)
|
||||||
|
|
||||||
|
def test_get_virt_memory_opt_str_lower(self):
|
||||||
|
self.assertEqual(up.get_virt_memory_opt('1tib'), 1024**4)
|
||||||
|
|
||||||
|
def test_get_virt_memory_opt_str_mixed(self):
|
||||||
|
self.assertEqual(up.get_virt_memory_opt('1MiB'), 1024**2)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue