Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
slapos.core
Commits
45ca8a58
Commit
45ca8a58
authored
Jun 05, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache lookup: removed old entry point, use prettytable
distribution check: added a few tests
parent
cc3c6c7a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
47 deletions
+71
-47
slapos/cache.py
slapos/cache.py
+25
-24
slapos/cli/cache.py
slapos/cli/cache.py
+1
-1
slapos/cli_legacy/cache.py
slapos/cli_legacy/cache.py
+0
-18
slapos/cli_legacy/entry.py
slapos/cli_legacy/entry.py
+0
-4
slapos/tests/distribution.py
slapos/tests/distribution.py
+45
-0
No files found.
slapos/cache.py
View file @
45ca8a58
...
...
@@ -7,6 +7,7 @@ import re
import
requests
import
sys
import
prettytable
from
slapos.grid
import
networkcache
from
slapos.grid.distribution
import
patched_linux_distribution
...
...
@@ -19,7 +20,7 @@ def looks_like_md5(s):
return
re
.
match
(
'[0-9a-f]{32}'
,
s
)
def
do_lookup
(
configp
,
software_url
):
def
do_lookup
(
configp
,
software_url
,
logger
):
cache_dir
=
configp
.
get
(
'networkcache'
,
'download-binary-dir-url'
)
if
looks_like_md5
(
software_url
):
...
...
@@ -28,39 +29,39 @@ def do_lookup(configp, software_url):
md5
=
hashlib
.
md5
(
software_url
).
hexdigest
()
try
:
req
=
requests
.
get
(
'%s/%s'
%
(
cache_dir
,
md5
))
except
requests
.
ConnectionError
:
print
'Cannot connect to cache at %s'
%
cache_dir
url
=
'%s/%s'
%
(
cache_dir
,
md5
)
logger
.
debug
(
'Connecting to %s'
,
url
)
req
=
requests
.
get
(
url
,
timeout
=
5
)
except
(
requests
.
Timeout
,
requests
.
ConnectionError
):
logger
.
critical
(
'Cannot connect to cache server at %s'
,
url
)
sys
.
exit
(
10
)
if
not
req
.
ok
:
if
req
.
status_code
==
404
:
print
'Object not in cache: %s'
%
software_url
logger
.
critical
(
'Object not in cache: %s'
,
software_url
)
else
:
print
'Error while looking object %s: %s'
%
(
software_url
,
req
.
reason
)
logger
.
critical
(
'Error while looking object %s: %s'
,
software_url
,
req
.
reason
)
sys
.
exit
(
10
)
entries
=
req
.
json
()
linux_distribution
=
patched_linux_distribution
()
if
not
entries
:
logger
.
info
(
'Object found in cache, but has no binary entries.'
)
return
ostable
=
sorted
(
ast
.
literal_eval
(
json
.
loads
(
entry
[
0
])[
'os'
])
for
entry
in
entries
)
pt
=
prettytable
.
PrettyTable
([
'distribution'
,
'version'
,
'id'
,
'compatible?'
])
header_printed
=
False
ostable
=
[]
for
entry
in
entries
:
meta
=
json
.
loads
(
entry
[
0
])
os
=
ast
.
literal_eval
(
meta
[
'os'
])
if
not
header_printed
:
print
'Software URL: %s'
%
meta
[
'software_url'
]
print
'MD5: %s'
%
md5
print
'-------------'
print
'Available for: '
print
'distribution | version | id | compatible?'
print
'-----------------+--------------+----------------+-------------'
header_printed
=
True
ostable
.
append
(
os
)
ostable
.
sort
()
linux_distribution
=
patched_linux_distribution
()
for
os
in
ostable
:
compatible
=
'yes'
if
networkcache
.
os_matches
(
os
,
linux_distribution
)
else
'no'
print
'%-16s | %12s | %s | %s'
%
(
os
[
0
],
os
[
1
],
os
[
2
].
center
(
14
),
compatible
)
pt
.
add_row
([
os
[
0
],
os
[
1
],
os
[
2
],
compatible
])
meta
=
json
.
loads
(
entries
[
0
][
0
])
logger
.
info
(
'Software URL: %s'
,
meta
[
'software_url'
])
logger
.
info
(
'MD5: %s'
,
md5
)
for
line
in
pt
.
get_string
(
border
=
True
,
padding_width
=
0
,
vrules
=
prettytable
.
NONE
).
split
(
'
\
n
'
):
logger
.
info
(
line
)
slapos/cli/cache.py
View file @
45ca8a58
...
...
@@ -27,4 +27,4 @@ class CacheLookupCommand(ConfigCommand):
def
take_action
(
self
,
args
):
configp
=
self
.
fetch_config
(
args
)
do_lookup
(
configp
,
args
.
software_url
)
do_lookup
(
configp
,
args
.
software_url
,
logger
=
self
.
app
.
log
)
slapos/cli_legacy/cache.py
deleted
100644 → 0
View file @
cc3c6c7a
# -*- coding: utf-8 -*-
import
argparse
import
ConfigParser
from
slapos.cache
import
do_lookup
def
cache_lookup
():
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
"configuration_file"
,
help
=
"SlapOS configuration file"
)
ap
.
add_argument
(
"software_url"
,
help
=
"Your software url or MD5 hash"
)
args
=
ap
.
parse_args
()
configp
=
ConfigParser
.
SafeConfigParser
()
configp
.
read
(
args
.
configuration_file
)
do_lookup
(
configp
,
args
.
software_url
)
slapos/cli_legacy/entry.py
View file @
45ca8a58
...
...
@@ -37,7 +37,6 @@ from slapos.cli_legacy.request import request
from
slapos.cli_legacy.remove
import
remove
from
slapos.cli_legacy.supply
import
supply
from
slapos.cli_legacy.format
import
main
as
format
from
slapos.cli_legacy.cache
import
cache_lookup
from
slapos.cli_legacy.slapgrid
import
runComputerPartition
as
instance
from
slapos.cli_legacy.slapgrid
import
runSoftwareRelease
as
software
from
slapos.cli_legacy.slapgrid
import
runUsageReport
as
report
...
...
@@ -165,8 +164,6 @@ def dispatch(command, is_node_command):
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'console'
:
call
(
console
,
config_path
=
USER_SLAPOS_CONFIGURATION
)
elif
command
==
'cache-lookup'
:
call
(
cache_lookup
,
config_path
=
GLOBAL_SLAPOS_CONFIGURATION
)
else
:
return
False
...
...
@@ -193,7 +190,6 @@ Client subcommands usage:
slapos request <instance-name> <software-url> [--configuration arg1=value1 arg2=value2 ... argN=valueN]
slapos supply <software-url> <node-id>
slapos console
slapos cache-lookup <software-url-or-md5>
Node subcommands usage:
slapos node
slapos node register <node-id>
...
...
slapos/tests/distribution.py
0 → 100644
View file @
45ca8a58
# -*- coding: utf-8 -*-
import
unittest
from
slapos.grid
import
distribution
class
TestDebianize
(
unittest
.
TestCase
):
def
test_debian_major
(
self
):
"""
On debian, we only care about major release.
All the other tuples are unchanged.
"""
for
provided
,
expected
in
[
((
'CentOS'
,
'6.3'
,
'Final'
),
None
),
((
'Ubuntu'
,
'12.04'
,
'precise'
),
None
),
((
'Ubuntu'
,
'13.04'
,
'raring'
),
None
),
((
'Fedora'
,
'17'
,
'Beefy Miracle'
),
None
),
((
'debian'
,
'6.0.6'
,
''
),
(
'debian'
,
'6'
,
''
)),
((
'debian'
,
'7.0'
,
''
),
(
'debian'
,
'7'
,
''
)),
]:
self
.
assertEqual
(
distribution
.
_debianize
(
provided
),
expected
or
provided
)
class
TestOSMatches
(
unittest
.
TestCase
):
def
test_centos
(
self
):
self
.
assertFalse
(
distribution
.
os_matches
((
'CentOS'
,
'6.3'
,
'Final'
),
(
'Ubuntu'
,
'13.04'
,
'raring'
)))
self
.
assertFalse
(
distribution
.
os_matches
((
'CentOS'
,
'6.3'
,
'Final'
),
(
'debian'
,
'6.3'
,
''
)))
def
test_ubuntu
(
self
):
self
.
assertFalse
(
distribution
.
os_matches
((
'Ubuntu'
,
'12.04'
,
'precise'
),
(
'Ubuntu'
,
'13.04'
,
'raring'
)))
self
.
assertTrue
(
distribution
.
os_matches
((
'Ubuntu'
,
'13.04'
,
'raring'
),
(
'Ubuntu'
,
'13.04'
,
'raring'
)))
self
.
assertTrue
(
distribution
.
os_matches
((
'Ubuntu'
,
'12.04'
,
'precise'
),
(
'Ubuntu'
,
'12.04'
,
'precise'
)))
def
test_debian
(
self
):
self
.
assertFalse
(
distribution
.
os_matches
((
'debian'
,
'6.0.6'
,
''
),
(
'debian'
,
'7.0'
,
''
)))
self
.
assertTrue
(
distribution
.
os_matches
((
'debian'
,
'6.0.6'
,
''
),
(
'debian'
,
'6.0.5'
,
''
)))
self
.
assertTrue
(
distribution
.
os_matches
((
'debian'
,
'6.0.6'
,
''
),
(
'debian'
,
'6.1'
,
''
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment