mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-09 20:20:31 -07:00
adds absent state for sdkmanager packages and setup for tests
This commit is contained in:
parent
ca3d11aade
commit
7349127609
5 changed files with 98 additions and 15 deletions
|
@ -36,7 +36,7 @@ class Package:
|
|||
if not isinstance(other, Package):
|
||||
return False
|
||||
|
||||
return self.name == other.name and self.version == other.version and self.description == other.description
|
||||
return self.name == other.name and self.version == other.version
|
||||
|
||||
def get_formatted(self):
|
||||
if self.version is None:
|
||||
|
@ -78,6 +78,14 @@ class AndroidSdkManager(object):
|
|||
return packages
|
||||
|
||||
def install_packages(self, packages):
|
||||
install_command_arg = ''.join(x.get_formatted() for x in packages)
|
||||
self.apply_packages_changes(packages, 'present')
|
||||
|
||||
def uninstall_packages(self, packages):
|
||||
self.apply_packages_changes(packages, 'absent')
|
||||
|
||||
def apply_packages_changes(self, packages, state):
|
||||
if len(packages) == 0:
|
||||
return
|
||||
command_arg = ''.join(x.get_formatted() for x in packages)
|
||||
with self.runner('state name') as ctx:
|
||||
ctx.run(name=install_command_arg)
|
||||
ctx.run(name=command_arg, state=state)
|
||||
|
|
|
@ -14,6 +14,13 @@ class AndroidSdk(StateModuleHelper):
|
|||
use_old_vardict = False
|
||||
output_params = ('installed')
|
||||
|
||||
@staticmethod
|
||||
def package_split(package):
|
||||
parts = package.split('=', maxsplit=1)
|
||||
if len(parts) > 1:
|
||||
return parts
|
||||
return parts[0], None
|
||||
|
||||
def __init_module__(self):
|
||||
self.sdkmanager = AndroidSdkManager(sdkmanager_runner(self.module))
|
||||
|
||||
|
@ -21,12 +28,12 @@ class AndroidSdk(StateModuleHelper):
|
|||
arg_pkgs = self.vars.package
|
||||
packages = []
|
||||
for arg_pkg in arg_pkgs:
|
||||
pkg, version = package_split(arg_pkg)
|
||||
pkg, version = AndroidSdk.package_split(arg_pkg)
|
||||
package = Package(pkg, version)
|
||||
packages.append(package)
|
||||
return packages
|
||||
|
||||
def __state_fallback__(self):
|
||||
def state_present(self):
|
||||
packages = self._parse_packages()
|
||||
installed = self.sdkmanager.get_installed_packages()
|
||||
pending_installation = []
|
||||
|
@ -34,13 +41,22 @@ class AndroidSdk(StateModuleHelper):
|
|||
for existing in installed:
|
||||
if existing.name == package.name:
|
||||
if existing.version == package.version:
|
||||
pass#do nothing, package exists
|
||||
pass # do nothing, package exists
|
||||
# else:
|
||||
# package exists, but needs to be updated/downgraded
|
||||
# package exists, but needs to be updated/downgraded
|
||||
else:
|
||||
pending_installation.append(package)
|
||||
self.sdkmanager.install_packages(pending_installation)
|
||||
|
||||
self.vars.installed = installed
|
||||
def state_absent(self):
|
||||
packages = self._parse_packages()
|
||||
installed = self.sdkmanager.get_installed_packages()
|
||||
to_be_deleted = []
|
||||
for package in packages:
|
||||
for existing in installed:
|
||||
if existing == package:
|
||||
to_be_deleted.append(package)
|
||||
self.sdkmanager.uninstall_packages(to_be_deleted)
|
||||
|
||||
def update_packages(self):
|
||||
pass
|
||||
|
@ -54,13 +70,6 @@ class AndroidSdk(StateModuleHelper):
|
|||
self.update_packages()
|
||||
|
||||
|
||||
def package_split(package):
|
||||
parts = package.split('=', maxsplit=1)
|
||||
if len(parts) > 1:
|
||||
return parts
|
||||
return parts[0], None
|
||||
|
||||
|
||||
def main():
|
||||
AndroidSdk.execute()
|
||||
|
||||
|
|
7
tests/integration/targets/android_sdk/aliases
Normal file
7
tests/integration/targets/android_sdk/aliases
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/3
|
||||
destructive
|
||||
needs/root
|
52
tests/integration/targets/android_sdk/tasks/tasks/setup.yml
Normal file
52
tests/integration/targets/android_sdk/tasks/tasks/setup.yml
Normal file
|
@ -0,0 +1,52 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
|
||||
- name: Install dependencies
|
||||
become: true
|
||||
package:
|
||||
name:
|
||||
- java-21-openjdk
|
||||
state: present
|
||||
|
||||
- name: Create Android SDK directory
|
||||
become: true
|
||||
file:
|
||||
path: "{{ android_sdk_location }}"
|
||||
state: directory
|
||||
owner: vagrant
|
||||
group: vagrant
|
||||
|
||||
- name: Check that sdkmanager is installed
|
||||
stat:
|
||||
path: "{{ android_sdk_location }}/cmdline-tools/latest/bin/sdkmanager"
|
||||
register: sdkmanager_installed
|
||||
|
||||
|
||||
- name: Install Android command line tools
|
||||
when: not sdkmanager_installed.stat.exists
|
||||
block:
|
||||
- name: Create Android SDK dir structure
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
state: "{{ item.state }}"
|
||||
with_items:
|
||||
- { path: "{{ android_cmdline_temp_dir }}", state: "directory" }
|
||||
- { path: "{{ android_sdk_location }}/cmdline-tools/latest", state: "directory" }
|
||||
|
||||
- name: Download Android command line tools
|
||||
unarchive:
|
||||
src: "{{ commandline_tools_link }}"
|
||||
dest: "{{ android_cmdline_temp_dir }}"
|
||||
remote_src: yes
|
||||
creates: "{{ android_cmdline_temp_dir }}/cmdline-tools"
|
||||
when: not sdkmanager_installed.stat.exists
|
||||
|
||||
|
||||
- name: Fix directory structure
|
||||
copy:
|
||||
src: "{{ android_cmdline_temp_dir }}/cmdline-tools/"
|
||||
dest: "{{ android_sdk_location }}/cmdline-tools/latest"
|
||||
remote_src: yes
|
||||
|
7
tests/integration/targets/android_sdk/vars/main.yml
Normal file
7
tests/integration/targets/android_sdk/vars/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
android_cmdline_temp_dir: "/tmp/cmdlinetools"
|
||||
android_sdk_location: /usr/local/android/sdk
|
||||
commandline_tools_link: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
|
Loading…
Add table
Reference in a new issue