Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
rsm
Commits
83f13d5b
Commit
83f13d5b
authored
Mar 19, 2020
by
LEFEBVREJP email
Browse files
#1
. Adding hostconfig pod and persistence.
parent
64605ac9
Pipeline
#94094
passed with stages
in 4 minutes and 44 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
rsmcore/CMakeLists.txt
View file @
83f13d5b
...
...
@@ -5,6 +5,7 @@ sessionworker.hh
sessioncontroller.hh
)
SET
(
SOURCES
hostconfig.cc
sessionworker.cc
sessioncontroller.cc
)
...
...
@@ -15,6 +16,7 @@ QT5_WRAP_CPP(MOC_FILES
SET
(
HEADERS
${
HEADERS
}
declspec.hh
hostconfig.hh
sessionlog.hh
)
TRIBITS_ADD_LIBRARY
(
rsmcore
...
...
rsmcore/hostconfig.cc
0 → 100644
View file @
83f13d5b
#include
"radixbug/bug.hh"
#include
"rsmcore/hostconfig.hh"
#include
<fstream>
namespace
rsm
{
QString
HostConfig
::
hostName
()
const
{
return
mHostName
;
}
void
HostConfig
::
setHostName
(
const
QString
&
hostName
)
{
mHostName
=
hostName
;
}
QString
HostConfig
::
proxyCommand
()
const
{
return
mProxyCommand
;
}
void
HostConfig
::
setProxyCommand
(
const
QString
&
proxyCommand
)
{
mProxyCommand
=
proxyCommand
;
}
int
HostConfig
::
port
()
const
{
return
mPort
;
}
void
HostConfig
::
setPort
(
int
port
)
{
mPort
=
port
;
}
HostConfig
::
HostConfig
()
{}
QString
HostConfig
::
userName
()
const
{
return
mUserName
;
}
void
HostConfig
::
setUserName
(
const
QString
&
userName
)
{
mUserName
=
userName
;
}
void
write_host_config
(
const
HostConfig
&
config
,
const
QString
&
path
)
{
std
::
ofstream
stream
;
stream
.
open
(
path
.
toStdString
());
if
(
!
stream
.
is_open
())
{
std
::
string
message
=
path
.
toStdString
();
message
=
message
+
" Failed to open."
;
throw
std
::
runtime_error
(
message
);
}
{
// host name
QString
var
=
config
.
hostName
();
stream
.
write
(
var
.
toStdString
().
c_str
(),
var
.
size
());
stream
<<
std
::
endl
;
}
{
// user name
QString
var
=
config
.
userName
();
stream
.
write
(
var
.
toStdString
().
c_str
(),
var
.
size
());
stream
<<
std
::
endl
;
}
{
// proxy command
QString
var
=
config
.
proxyCommand
();
stream
.
write
(
var
.
toStdString
().
c_str
(),
var
.
size
());
stream
<<
std
::
endl
;
}
{
// port number
stream
<<
config
.
port
()
<<
std
::
endl
;
}
stream
.
close
();
}
void
read_host_config
(
HostConfig
&
config
,
const
QString
&
path
)
{
std
::
ifstream
stream
;
stream
.
open
(
path
.
toStdString
());
if
(
!
stream
.
is_open
())
{
std
::
string
message
=
path
.
toStdString
();
message
=
message
+
" Failed to open."
;
throw
std
::
runtime_error
(
message
);
}
{
// host name
std
::
string
line
;
std
::
getline
(
stream
,
line
);
radix_tagged_line
(
"Reading host name: "
<<
line
);
config
.
setHostName
(
line
.
c_str
());
}
{
// user name
std
::
string
line
;
std
::
getline
(
stream
,
line
);
radix_tagged_line
(
"Reading user name: "
<<
line
);
config
.
setUserName
(
line
.
c_str
());
}
{
// proxy command
std
::
string
line
;
std
::
getline
(
stream
,
line
);
radix_tagged_line
(
"Reading proxy command: "
<<
line
);
config
.
setProxyCommand
(
line
.
c_str
());
}
{
// port number
std
::
string
line
;
std
::
getline
(
stream
,
line
);
bool
ok
=
false
;
int
port
=
QString
(
line
.
c_str
()).
toInt
(
&
ok
);
radix_tagged_line
(
"Reading port number: "
<<
line
);
if
(
!
ok
)
{
port
=
22
;
// default ssh port
radix_tagged_line
(
"
\t
defaulting to ssh port (22)"
);
}
config
.
setPort
(
port
);
}
}
}
// namespace rsm
rsmcore/hostconfig.hh
0 → 100644
View file @
83f13d5b
#ifndef RSMCORE_HOSTCONFIG_HH_
#define RSMCORE_HOSTCONFIG_HH_
#include
<QString>
namespace
rsm
{
/**
* @brief The HostConfig class
* POD for host configuration design to simplify persistence
*/
class
HostConfig
{
protected:
QString
mUserName
;
QString
mHostName
;
QString
mProxyCommand
;
int
mPort
=
22
;
// default ssh port
public:
HostConfig
();
QString
userName
()
const
;
void
setUserName
(
const
QString
&
userName
);
QString
hostName
()
const
;
void
setHostName
(
const
QString
&
hostName
);
QString
proxyCommand
()
const
;
void
setProxyCommand
(
const
QString
&
proxyCommand
);
int
port
()
const
;
void
setPort
(
int
port
);
};
// class
/**
* @brief write_host_config
* @param config const HostConfig&
* @param path file path to write contents to
*/
void
write_host_config
(
const
HostConfig
&
config
,
const
QString
&
path
);
/**
* @brief read_host_config
* @param config HostConfig&
* @param path file path to read contents from
*/
void
read_host_config
(
HostConfig
&
config
,
const
QString
&
path
);
}
// namespace rsm
#endif
/* RSMCORE_HOSTCONFIG_HH_ */
rsmcore/tests/CMakeLists.txt
View file @
83f13d5b
INCLUDE
(
GoogleTest
)
ADD_GOOGLE_TEST
(
tstHostConfig.cc NP 1
)
ADD_GOOGLE_TEST
(
tstSessionWorker.cc NP 1
)
ADD_GOOGLE_TEST
(
tstSessionController.cc QTCOREAPP NP 1
)
rsmcore/tests/tstHostConfig.cc
0 → 100644
View file @
83f13d5b
#include
"gtest/gtest.h"
#include
"rsmcore/hostconfig.hh"
#include
"radixcore/system.hh"
using
namespace
rsm
;
TEST
(
RSM
,
HostConfig
)
{
{
HostConfig
config
;
config
.
setHostName
(
"romulus.ornl.gov"
);
config
.
setUserName
(
"jap"
);
config
.
setProxyCommand
(
"corkscrew snowman.ornl.gov 3128 %h %p"
);
write_host_config
(
config
,
"host_romulus.cfg"
);
}
{
HostConfig
config
;
config
.
setPort
(
40
);
config
.
setProxyCommand
(
"blablabla"
);
read_host_config
(
config
,
"host_romulus.cfg"
);
EXPECT_EQ
(
"romulus.ornl.gov"
,
config
.
hostName
());
EXPECT_EQ
(
"jap"
,
config
.
userName
());
EXPECT_EQ
(
22
,
config
.
port
());
EXPECT_EQ
(
"corkscrew snowman.ornl.gov 3128 %h %p"
,
config
.
proxyCommand
());
}
// radix::remove_file("host_romulus.cfg");
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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