Skip to content
This repository has been archived by the owner on Jan 13, 2020. It is now read-only.
/ accelpy Public archive

Commit

Permalink
1.0.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JGoutin committed Jul 10, 2019
1 parent b1a93ae commit 6a4c059
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Build generated files
docs/_build/
docs/cli_help.rst
build/
dist/
.eggs/
Expand Down
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
sudo: required
language: python
services: docker
Expand All @@ -9,14 +10,15 @@ python:

install:
# Python environment
- "python -m pip install --upgrade setuptools pip wheel pytest-cov codecov molecule[docker]"
- "python -m pip install --upgrade setuptools pip wheel pytest-cov codecov
molecule[docker] --pre"

# Installs all package dependencies
- "python -m pip install -e ."

script:
# Runs tests
- 'py.test -v -m "not require_csp" --cov=accelpy --cov-report=term-missing'
- 'pytest -v -m "not require_csp" --cov=accelpy --cov-report=term-missing'

after_success:
# Sends coverage to codecov.io
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[![Build Status](https://travis-ci.org/Accelize/accelpy.svg?branch=master)](https://travis-ci.org/Accelize/accelpy)
![AWS Build Status](https://codebuild.eu-west-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiK3JOY01yMVNqYnc3ZTBiT0JqUWNQb3VJdFRmL3FJYllPeXBZUTZ0cEFlaFZBNWxkUmlPS2QrYm1NcytsYkQ3NE4rbmx5MXpxNjF0T3ZGbzY3M0gxczFFPSIsIml2UGFyYW1ldGVyU3BlYyI6IkNNdlVYMVgrUFZIZGZyQUUiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
[![codecov](https://codecov.io/gh/Accelize/accelpy/branch/master/graph/badge.svg)](https://codecov.io/gh/Accelize/accelpy)
[![Documentation Status](https://readthedocs.org/projects/accelpy/badge/?version=latest)](https://accelpy.readthedocs.io/en/latest/?badge=latest)
[![PyPI](https://img.shields.io/pypi/v/accelpy.svg)](https://pypi.org/project/accelpy)

# Overview

*accelpy* is an FPGA accelerated applications provisioning utility.
Expand Down
2 changes: 1 addition & 1 deletion accelpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
__version__ = '1.0.0'
__version__ = '1.0.0-beta.1'
__copyright__ = "Copyright 2018 Accelize"
__licence__ = "Apache 2.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ apt-get install -y --no-install-recommends \
ca-certificates \
gnupg \
python3 \
sudo && \
sudo \
systemd \
&& \
apt-get clean && \
groupadd -g 1001 fpgauser
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ lint:
name: yamllint
platforms:
- name: docker
image: jrei/systemd-ubuntu:18.04
image: ubuntu:bionic
privileged: true
override_command: false
volume_mounts:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
command: "/lib/systemd/systemd"
environment:
container: docker

- name: podman
image: jrei/systemd-ubuntu:18.04
image: ubuntu:bionic
privileged: true
override_command: false
volume_mounts:
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
command: "/lib/systemd/systemd"
environment:
container: docker

provisioner:
name: ansible
lint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts()


def test_service_running(host):
def test_configuration_ready(host):
"""
Test if service is running.
Test if service configuration properly generated.
"""
# Check service
service = host.service('accelize_container')
assert service.is_running
assert service.is_enabled
conf = host.file('/etc/systemd/system/accelize_container.service')
assert conf.exists
assert conf.contains('--env FPGA_SLOTS=0')
assert conf.contains('-p 8080:8080/tcp')
assert (conf.contains('--privileged') or
conf.contains('--device') or
conf.contains('--mount'))
8 changes: 5 additions & 3 deletions accelpy/_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@
'enabled, the application must handle the DRM itself using '
'the Accelize DRM library.'
),
'conf_path': dict(
desc='Configuration file path.'
'conf': dict(
desc='Accelize DRM configuration.',
value_type=dict,
default={},
),
}
}
Expand Down Expand Up @@ -146,7 +148,7 @@ def get(self, section, key, env=None):
env (str): Environment. None for use default environment value.
Returns:
str: value
Value
"""
# Return specific environment value
try:
Expand Down
6 changes: 5 additions & 1 deletion accelpy/_common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# coding=utf-8
"""Global configuration"""
from json import dump as _json_dump, load as _json_load
from os import fsdecode as _fsdecode, symlink as _symlink, chmod as _chmod
from os import (fsdecode as _fsdecode, symlink as _symlink, chmod as _chmod,
makedirs as _makesdirs)
from os.path import (
expanduser as _expanduser, isdir as _isdir, realpath as _realpath)
from collections.abc import Mapping as _Mapping
Expand All @@ -19,6 +20,9 @@

#: User configuration directory
HOME_DIR = _expanduser('~/.accelize')

# Ensure directory exists and have restricted access rights
_makesdirs(HOME_DIR, exist_ok=True)
_chmod(HOME_DIR, 0o700)


Expand Down
1 change: 1 addition & 0 deletions accelpy/_hashicorp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def _get_last_version(cls):
last_release['signature_url'] = f"{checksum_url}.sig"

# Cache result
makedirs(cls._install_dir(), exist_ok=True)
json_write(last_release, info_cache)

else:
Expand Down
23 changes: 19 additions & 4 deletions accelpy/_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(self, name=None, application=None, provider=None,
self._config_dir = join(CONFIG_DIR, name)
user_parameters_json = join(self._config_dir, 'user_parameters.json')
self._output_json = join(self._config_dir, 'output.json')
self._accelize_drm_conf_json = join(
self._config_dir, 'accelize_drm_conf.json')

# Create a new configuration
config_exists = isdir(self._config_dir)
Expand Down Expand Up @@ -259,7 +261,7 @@ def _app(self, section, key):
key (str): Definition key.
Returns:
str: Value
Value
"""
return self._application.get(section, key, env=self._provider)

Expand Down Expand Up @@ -294,6 +296,20 @@ def _ansible(self):
# Lazy import: May not be used all time
from accelpy._ansible import Ansible

# Get Accelize DRM configuration
accelize_drm_enable = self._app('accelize_drm', 'use_service')
accelize_drm_conf = self._app('accelize_drm', 'conf')

if accelize_drm_enable and not accelize_drm_conf:
# Check configuration presence instead of wait role failure
raise ConfigurationException(
'Application definition section "accelize_drm" require '
'"conf" value to be specified if "use_service" is '
'specified.')

json_write(accelize_drm_conf, self._accelize_drm_conf_json)

# Set Ansible variables
variables = dict(
fpga_image=self._app('fpga', 'image'),
fpga_driver=self._app('fpga', 'driver'),
Expand All @@ -304,9 +320,8 @@ def _ansible(self):
package_name=self._app('package', 'name'),
package_version=self._app('package', 'version'),
package_repository=self._app('package', 'repository'),
accelize_drm_disabled=not self._app(
'accelize_drm', 'use_service'),
accelize_drm_conf_src=self._app('accelize_drm', 'conf_path'),
accelize_drm_disabled=not accelize_drm_enable,
accelize_drm_conf_src=self._accelize_drm_conf_json,
accelize_drm_cred_src=join(self._config_dir, 'cred.json')
)

Expand Down
14 changes: 11 additions & 3 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
# AWS CodeBuild
version: 0.2

env:
parameter-store:
XLZCRYPT_KEY: "xlzcrypt_key"

phases:
install:
runtime-versions:
python: 3.7
commands:
- python3 -m pip install pytest
- python3 -m pip install -e .
- $CODEBUILD_SRC_DIR_toolbox/install.py
- xlz install drmlib_cred_json=~/.accelize accelpy_common_tf
- python3 -m pip install -Uq setuptools pip wheel pytest
- python3 -m pip install -qe .

build:
commands:
- pytest -v -m require_csp
- pytest -s -m require_csp
16 changes: 16 additions & 0 deletions docs/_static/accelize.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.wy-side-nav-search {
background-image: url("background.png");
background-repeat: no-repeat;
background-size: contain;
background-position: top;
background-color: #ea7222
}

.wy-side-nav-search input[type="text"] {
border-color: #ea7222
}

.wy-side-nav-search > a, .wy-side-nav-search .wy-dropdown > a {
color: #ea7222
}

Binary file added docs/_static/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

/* Hide "On Read the Docs" section from versions menu */
div.rst-versions > div.rst-other-versions > div.injected > dl:nth-child(3) {
display: none;
}

/* Hide "On GitHub" section from versions menu */
div.rst-versions > div.rst-other-versions > div.injected > dl:nth-child(4) {
display: none;
}
Binary file added docs/_static/favicon.ico
Binary file not shown.
Binary file added docs/_static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 31 additions & 1 deletion docs/application_definition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,37 @@ This section define the DRM service configuration.
using the Accelize DRM library (See
`Accelize documentation <https://www.accelize.com/docs>`_). `false` if not
specified.
* `conf_path` (string): Path to Accelize DRM `conf.json`.
* `conf` (dict): Content of Accelize DRM `conf.json` (YAML or JSON formatted).

.. code-block::yaml
:caption: Passing the Accelize DRM conf.json: YAML formatted
accelize_drm:
conf:
licensing:
url: https://master.metering.accelize.com
drm:
frequency_mhz: 125
drm_ctrl_base_addr: 0
design:
boardType: ISV custom data
.. code-block::yaml
:caption: Passing the Accelize DRM conf.json: JSON formatted
accelize_drm:
conf: {
"licensing": {
"url": "https://master.metering.accelize.com"
},
"drm": {
"frequency_mhz": 125,
"drm_ctrl_base_addr": 0,
},
"design": {
"boardType": "ISV custom data"
}
}
Provider specific override
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
23 changes: 16 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Sphinx documentation """


# -- Path setup --------------------------------------------------------------

from os.path import abspath, dirname
Expand All @@ -16,6 +17,7 @@
from setup import PACKAGE_INFO
SPHINX_INFO = PACKAGE_INFO['command_options']['build_sphinx']


# -- Project information -----------------------------------------------------

project = SPHINX_INFO['project'][1]
Expand All @@ -25,7 +27,7 @@
release = SPHINX_INFO['release'][1]


# -- Dynamically generates documentation from Apyfal CLI help ----------
# -- Dynamically generates documentation from CLI help ----------

from subprocess import check_output

Expand All @@ -40,7 +42,7 @@ def _generates_rst(rst_path, content):
"""
with open(rst_path, 'wt', encoding='utf-8') as rst_file:
rst_file.write('\n'.join(
[".. WARNING:\n This file is autogenerated"
[".. WARNING: This file is autogenerated"
", do not edit it manually\n"] + content))


Expand All @@ -54,13 +56,14 @@ def generates_cli_help(rst_path):
cli = [sys.executable or 'python3', '../accelpy/__main__.py']
commands = (
'', 'init', 'plan', 'apply', 'destroy', 'build', 'private_ip',
'public_ip', 'ssh_user', 'ssh_private_key', 'ssh_agent_add',
'ssh_agent_remove', 'list', 'lint')
'public_ip', 'ssh_user', 'ssh_private_key', 'list', 'lint')
content = [
'CLI\n',
'====\n',
'CLI',
'====',
'',
'This section provides full CLI help (from ``--help``)',
'for each command.\n']
'for each command.',
'']

for command in commands:
cli_help = check_output(
Expand Down Expand Up @@ -92,6 +95,12 @@ def generates_cli_help(rst_path):

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_theme_options = {'prev_next_buttons_location': None}
html_favicon = '_static/favicon.ico'
html_logo = '_static/logo.png'
html_show_sourcelink = False
html_show_sphinx = False
html_context = {'css_files': ['_static/accelize.css']}

# -- Options for HTMLHelp output ---------------------------------------------

Expand Down
10 changes: 8 additions & 2 deletions tests/test_container_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ application:
type: container_service
version: 1.0.0

firewall_rules:
firewall_rules:
- start_port: 8080
end_port: 8080
protocol: tcp
Expand All @@ -21,7 +21,13 @@ package:
type: container_image

accelize_drm:
conf_path: /home/fedora/Documents/git/drmlib/tests/utils/conf.json
conf:
design:
boardType: DRM_125
licensing:
url: https://master.metering.accelize.com
drm:
frequency_mhz: 125

test:
shell: curl -sS $(accelpy public_ip):8080
Loading

0 comments on commit 6a4c059

Please sign in to comment.